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

Link to comment
Share on other sites

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