Jump to content

[SOLVED] The first of records my query isnt showing up


newbreed65

Recommended Posts

Hey Everyone

 

I'm having a problem with the movie part of the page the link will take you too.

 

http://bulletsnoctane.co.uk/people/person.php?id=5

 

I'm trying to show all the movie that the person has been attached too but for some reason the first record in the query doesn't show

 

it should be

 

terminator salvation

dark knight

batman begins

 

not just the last 2 movies, I've double checked the query in phpmyadmin and all 3 records show up

 

<h3>Movies</h3>
<?php      

$sql = "SELECT *
       FROM casts JOIN movie 
   ON (casts.movie=movie.id)
   JOIN roles 
   ON (casts.role=roles.id)
   WHERE person_id=" . $id . "
   ORDER BY released DESC";
$result = mysql_query($sql) 
  or die(mysql_error());
$cast = mysql_fetch_array($result);

  if (mysql_num_rows($result) == 0) {
      echo "  <em>currently not attached to any movies</em>";
    	$table = "";
} else {

$table = "<table>";  
  while ($cast = mysql_fetch_array($result)) {

		$date1 = $cast['released'];
		$date2 = explode("-",date("Y-m-d",strtotime($date1)));//splits up the date

$table .= "<tr><td>" .
              $date2[0] . "</td>" .
		  '<td><a href="/movies/movie.php?id=' . $cast['movie'] . '">' .
              $cast['name'] . "</a></td><td>" .
              $cast['role_name'] . "</td><td>" .
              $cast['char_name'] . "</td>";
  }
}
  $table .= "</table>";

echo $table;
?>
</div>

Try deleting $cast = mysql_fetch_array($result); (the one before the loop)

To explain, here you are reading the first row from the table and placing the pointer there then in the loop you are looping through all the rows starting one after the pointer.

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.