matthew798 Posted April 3, 2011 Share Posted April 3, 2011 Yeah thats right! I think it should work my way! include '../dbconnect_form_fields.php'; $res = mysql_query("SELECT * FROM form_fields") or die(mysql_error()); while($res = mysql_fetch_assoc( $res )){ echo "<option value='".$res['id']."' > ".$res['field']." ".$res['price']."</option>\n"; } Why is this only returning the first row of the values in my DB? Why wont it display the second one as well?(as there are only 2) Thnx champs! Link to comment https://forums.phpfreaks.com/topic/232606-loop-not-working-like-i-think-it-should/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2011 Share Posted April 4, 2011 The following are the most likely causes (from most to least likely) - 1) That's not the whole actual code and you either have - 1a) a line of code, between where you execute the query and where you start the loop, that is fetching and discarding a row, or 1b) some code in the while() loop that is overwriting the result resource so that it doesn't exist the second time through the loop, 2) You actually only have one matching row in your database table, or 3) That's not the actual query that is producing the result resource that your loop is using, or 4) Something in your data looks like HTML and is breaking the HTML and the other row of data might be visible in the 'view source' of the page in your browser. Link to comment https://forums.phpfreaks.com/topic/232606-loop-not-working-like-i-think-it-should/#findComment-1196412 Share on other sites More sharing options...
kickstart Posted April 4, 2011 Share Posted April 4, 2011 Hi You are over writing the queries results set with the first results:- while($res = mysql_fetch_assoc( $res )) Change one of them to a different variable name (and other lines that refer to the one you change). All the best Keith Link to comment https://forums.phpfreaks.com/topic/232606-loop-not-working-like-i-think-it-should/#findComment-1196505 Share on other sites More sharing options...
PFMaBiSmAd Posted April 4, 2011 Share Posted April 4, 2011 LOL - 1b Link to comment https://forums.phpfreaks.com/topic/232606-loop-not-working-like-i-think-it-should/#findComment-1196565 Share on other sites More sharing options...
matthew798 Posted April 4, 2011 Author Share Posted April 4, 2011 i know about that i just forgot to mention it. I had tried that as a last ditch attempt to eliminate me being retarded and i guesse in doing it I only proved that i am .. Link to comment https://forums.phpfreaks.com/topic/232606-loop-not-working-like-i-think-it-should/#findComment-1196916 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.