NewbieBryan Posted July 26, 2009 Share Posted July 26, 2009 This piece of code loops through a table that I have and returns all the info stored therin, EXCEPT for the first row in the table. From my basic grasp of arrays I know (read:think) that I need to subtract "1" from somewhere to get it to show all the results but I am battling. Any help would be appretiated. $query = "SELECT * FROM $DBtable"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo $row['ID'] . "---". $row['First'] . "---". $row['Sur'] . "---". $row['Com']; echo "<p>"; } Link to comment Share on other sites More sharing options...
GingerRobot Posted July 26, 2009 Share Posted July 26, 2009 You need to remove this line: $row = mysql_fetch_array($result) or die(mysql_error()); As the manual page says, the function returns the next row in the result set and advances the internal pointer. So before your loop runs, you're already pointing at the second row in the result set. Edit: I shall move this topic to the FAQ/Code snippet repository once you've seen it and marked it solved. It's a fairly frequent question -- i guessed the question and answer from your title. Link to comment Share on other sites More sharing options...
NewbieBryan Posted July 26, 2009 Author Share Posted July 26, 2009 Tx GingerRobot, Removed that line and it worked like a charm:... Bit frustrating though, I am teaching myself PHP and MySQL and have been using this site as a reference. http://www.tizag.com/mysqlTutorial/mysqlselect.php This is not the first time that some of the code example has been "not 100% correct".... Are there any other sites that you could point me to, and or "learning" suggestions? Tx again, Bryan Link to comment Share on other sites More sharing options...
GingerRobot Posted July 26, 2009 Share Posted July 26, 2009 I don't actually see the line i recommended you to take out in the code on that site. However, i'd personally recommend the tutorials on the main site here: www.phpfreaks.com/tutorials. You'll find an excellent tutorial on basic database handling here. Link to comment Share on other sites More sharing options...
NewbieBryan Posted July 26, 2009 Author Share Posted July 26, 2009 http://www.tizag.com/mysqlTutorial/mysqlfetcharray.php :-[sorry GingerRobot, I have been battling with that one so so I had progressed to the next page: Correct (incorrect) link above... Have headed over to the tutorials section, they look great - Thank you for the advice - Have a great Sunday.. Link to comment Share on other sites More sharing options...
Recommended Posts