Jump to content

Loop not working like i think it should


matthew798

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.