tyler_durden Posted October 17, 2010 Share Posted October 17, 2010 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 />"; } Quote Link to comment https://forums.phpfreaks.com/topic/216089-why-is-this-code-skipping-the-first-record/ Share on other sites More sharing options...
Alex Posted October 17, 2010 Share Posted October 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216089-why-is-this-code-skipping-the-first-record/#findComment-1123055 Share on other sites More sharing options...
tyler_durden Posted October 17, 2010 Author Share Posted October 17, 2010 Doh! Thanks, I feel stupid. Very new to coding. Quote Link to comment https://forums.phpfreaks.com/topic/216089-why-is-this-code-skipping-the-first-record/#findComment-1123120 Share on other sites More sharing options...
tyler_durden Posted October 18, 2010 Author Share Posted October 18, 2010 One last thing, how in the world do I pull just the values in the field labeled "field_item_id_value" into the array? That's the only data I need. Quote Link to comment https://forums.phpfreaks.com/topic/216089-why-is-this-code-skipping-the-first-record/#findComment-1123183 Share on other sites More sharing options...
Alex Posted October 18, 2010 Share Posted October 18, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/216089-why-is-this-code-skipping-the-first-record/#findComment-1123185 Share on other sites More sharing options...
tyler_durden Posted October 18, 2010 Author Share Posted October 18, 2010 I see, I was thinking I had to grab everything to loop. I was only outputting the nid for testing to compare the records. I need to see everything step by step to understand. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/216089-why-is-this-code-skipping-the-first-record/#findComment-1123193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.