Re: loop? or conditional problem

From: Date: Sun, 02 Sep 2001 01:55:47 +0000
Subject: Re: loop? or conditional problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-65623@lists.php.net to get a copy of this message
Your SELECT statement is returning way more rows than you expect, I think, since it will return the number of users times the number of members minus however many there are that have the same id... I don't think you wanted that... I suspect you want a sub-select where you don't get any users who are members, or maybe no members who are users... MySQL *might* let you do: select ... from members where not id in (select id from users) OTOH, I don't really understand what you are trying to do in the first place, but I suspect there's a much easier way to do it... -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm ----- Original Message ----- From: Syaggie <syaggie@usol.com> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Saturday, September 01, 2001 8:26 AM Subject: loop? or conditional problem > Okay the the script is attached below. i am baffled at the problem. as you > can see the script does a rather simplistic generation of passwords. it > then writes them into two files. > > the problem is the first time i run (i am running it stand alone) it works > fine and the result is two files with 32 entries (and the mysql entries are > also correct). the second time i run it. i (there should be 44 new entries > make one file with 76 entries and another with 44) > > however what i get is a file with 1233 entries and another with 1201. > > now i admit the code is not beautiful but my concern is more of what is > causing this. i have checked the variables both $i and $rows appear fine. > > when i look at the text files what i see is it assigns the 44 entries and > then repeats them. all i can figure is it is the conditional or whiel loop? > why does it work perfect the first time?? > > > <?php > mysql_connect("localhost:/var/run/mysql/mysql.sock"); > mysql_select_db("VQRGDATA"); > $letter = array("Gob", "Lol", "woZ", "Kop", > "MoS", "tRu", "SAw", "NoR", > "TEf","TaF", "JoP", "lOg", "tAn", > "FiSH", "cAT", "VAn", "bAb", "Mob", > "KorN", "BeAt", "roSe", "KlaP", "iZ", > "GEr", "HaT", "ZaaM", "toAd", "emU"); > $results = mysql_query("SELECT members.id, members.lname FROM members, users > WHERE users.id <> members.id"); > $rows= mysql_num_rows($results); > if($rows != 0) > { > while($info = mysql_fetch_array($results)) > { > if($info[0] != 0) > { > $ids[] = $info[0]; > $lnames[] = $info[1]; > } > } > mysql_free_result($results); > $i=0; > while($i < $rows-1) > { > srand((double) microtime() * 1000000); > $pass_letter_key = array_rand($letter); > srand((double) microtime() * 1000000); > $pass_num1 = mt_rand(0, 26); > srand((double) microtime() * 1000000); > $pass_num2 = mt_rand(100, 926); > $strip = trim($lnames[$i]); > $lower = strtolower($strip); > $infochop = substr($lower, -5, 4); > $username = $infochop.$pass_num2; > $password = $pass_num1. $letter[$pass_letter_key].$pass_num2; > $respass = mysql_query("SELECT password FROM users WHERE > password='$password'"); > $pass_row = mysql_num_rows($respass); > if(!$pass_row) > { > mysql_query("INSERT INTO users(id, username,password) VALUES('$ids[$i]', > '$username', '$password') "); > $complete = fopen("complete.txt", "a+"); > $input[] = $ids[$i]."\t".$username."\t".$password."\n"; > fputs($complete, $input[$i]); > fclose($complete); > $i++; > } > mysql_free_result($respass); > > } > } > $new = implode("", $input); > $newtxt = fopen("new.txt", "w"); > fputs($newtxt, $new); > fclose($newtxt); > ?> >

« previous php.general (#65623) next »