Jump to content

Weird problem with SELECT command..Help!


patheticsam

Recommended Posts

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

<?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.

$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.

Archived

This topic is now archived and is closed to further replies.

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