patheticsam Posted February 18, 2010 Share Posted February 18, 2010 Hi! It seems I'm having a really weird problem with SQL SELECT command....I have table into a mySQL DB wich as 4 entry in it. I created the select command to retrieve the data and only 3 of the 4 entry is displaying. If I enter a 5th entry. Only 4 of the 5 will display....? Here's the code : <?php mysql_connect("server", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); $data = mysql_query("SELECT * FROM artists") or die(mysql_error()); $info = mysql_fetch_array( $data ); while($info = mysql_fetch_array( $data )) { echo " <center> <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"400\"> <tr> <td width=\"150\"><img src=\"admin/artists photo/".$info['photo']."\" /></td> <td width=\"250\"><h1>".$info['artist']."</h1></td> </tr> </table><br /> </center> "; } ?> If anyone sees what I did wrong it would be really appreciated! Thanks! Link to comment https://forums.phpfreaks.com/topic/192565-weird-problem-with-select-commandhelp/ Share on other sites More sharing options...
premiso Posted February 18, 2010 Share Posted February 18, 2010 <?php mysql_connect("server", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); $data = mysql_query("SELECT * FROM artists") or die(mysql_error()); //$info = mysql_fetch_array( $data ); while($info = mysql_fetch_array( $data )) { echo " <center> <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"400\"> <tr> <td width=\"150\"><img src=\"admin/artists photo/".$info['photo']."\" /></td> <td width=\"250\"><h1>".$info['artist']."</h1></td> </tr> </table><br /> </center> "; } ?> You are incrementing the data with the commented out section. It should work if you remove that. Link to comment https://forums.phpfreaks.com/topic/192565-weird-problem-with-select-commandhelp/#findComment-1014538 Share on other sites More sharing options...
roopurt18 Posted February 18, 2010 Share Posted February 18, 2010 $info = mysql_fetch_array( $data ); while($info = mysql_fetch_array( $data )) Each time you call mysql_fetch_array() you retrieve a row from the results. Notice how you have a call to mysql_fetch*() before the loop and you do nothing with info? Yah. That means you're throwing the first record away into the black void that is your computer's memory. Link to comment https://forums.phpfreaks.com/topic/192565-weird-problem-with-select-commandhelp/#findComment-1014539 Share on other sites More sharing options...
patheticsam Posted February 18, 2010 Author Share Posted February 18, 2010 Got it! thnx! Link to comment https://forums.phpfreaks.com/topic/192565-weird-problem-with-select-commandhelp/#findComment-1014544 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.