Re: running query through while loop returns same variables

From: Date: Wed, 10 Oct 2001 20:10:24 +0000
Subject: Re: running query through while loop returns same variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-70730@lists.php.net to get a copy of this message
The mysql_fetch_row() runction has to go inside the loop. Each time it's accessed (once during each loop) it grabs the next result row =) Since it's outside the loop (just before it starts), it only grabbed the first result row, and keeps those values for the whole loop =) Move the mysql_fetch_row() line of code down 2 line (just under the "while" function), and it should work =) Tom Beidler wrote: > I'm trying to run a query through a while loop and keep getting the same > variables. I've tried flushing out using mysql_free_result without much > success. Here's the code to give you an idea of what I'm trying to do. > > while (list($key, $value) = each($year_array)) { > $js_firstgroup .= "group[$counter1][$counter2]=new Option(\"Now Select a > Make\",\" \");\n"; > > $make_query = "SELECT make FROM application WHERE year_in >= $value AND > year_out <= $value ORDER BY make"; > $make_result = mysql_query ($make_query) > or die ("Cannot get make."); > $make_row = mysql_fetch_array ($make_result); > while ($make_row = mysql_fetch_array ($make_result)) { > $make = $make_row["make"]; > $counter2++; > $counter3++; > $js_firstgroup .= "group[$counter1][$counter2]=new > Option(\"$make\",\"$counter3\");\n"; > } > $js_firstgroup .= "\n"; > $counter1++; > $counter2 = 0; > mysql_free_result ($make_result); > } > > It apears that I keep looping through the first query array everytime. > > Any help appreciated. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- - Tim PHP Galaxy: http://www.phpgalaxy.com/ The LavaWarp Engine: http://www.phpgalaxy.com/engine.php3 BitSearch: http://www.phpgalaxy.com/bitsearch.php3 MetaWarp: http://www.phpgalaxy.com/metawarp.php3 PhotoRate: http://www.phpgalaxy.com/photorate.php3 Earn $10 per order selling these scripts on your site! http://www.phpgalaxy.com/aff/

« previous php.general (#70730) next »