Jump to content

Why is this code skipping the first record?


tyler_durden

Recommended Posts

I have three records in this table, yet the script below only displays two records, skipping the first item.  I have tried it in other fields also, and it is always skipping the first record?

$result = mysql_query("SELECT * FROM `content_type_ads`");

$row = mysql_fetch_array( $result );

while($row = mysql_fetch_array($result)){
echo $row['nid']. " - ". $row['field_item_id_value'];
echo "<br />";
}

Link to comment
Share on other sites

It's skipping the first record because the first record is being grabbed by this line:

 

$row = mysql_fetch_array( $result );

 

and nothing is being done with it. Just remove that line and it should work fine.

Link to comment
Share on other sites

Select only the data you need from the database in your query:

 

$result = mysql_query("SELECT field_item_id_value FROM `content_type_ads`");

 

(note: In your code, unless you've changed it since the OP, you're also using the nid column)

Link to comment
Share on other sites

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.