Jump to content

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.