Page 1 of 1

echoing an array

Posted: Fri May 22, 2009 1:00 am
by dlusiondone
Hi guys,

My tables looks like this:

movieID movie_title
1 Seven Pounds
2 Tranformers
3 Angels & Demons
4 Bamboozelled
5 Waltz With Bashir

Re: echoing an array

Posted: Fri May 22, 2009 1:03 am
by dlusiondone
Hi guys,

My tables looks like this:

movieID movie_title
1 Seven Pounds
2 Tranformers
3 Angels & Demons
4 Bamboozelled
5 Waltz With Bashir

And my code looks like this:

<?php

while($row = mysql_fetch_array($result))
{
echo $row['movieID']. " - " .$row['movie_title'];
echo "<br />" ;
}

?>

But for some reason it only returns this:

2 - Tranformers
3 - Angels & Demons
4 - Bamboozelled
5 - Waltz With Bashir

As you can see the first table entry is missing! Any suggestions?

Thanks in advance.

Re: echoing an array

Posted: Fri May 22, 2009 1:07 am
by Gabriel
Welcome to the forums. Please use the proper [ code=php ] ... [ /code ] tags.
 
What kind of SQL query are you using?
 

Code: Select all

SELECT * FROM movies -- Anything like this?

Re: echoing an array

Posted: Fri May 22, 2009 1:28 am
by jaoudestudios
Whats the code before, just as Gabriel said how is your query? I have seen this problem many times before when mysql_fetch_assoc is used twice on the same resource.

Re: echoing an array

Posted: Fri May 22, 2009 2:33 am
by dlusiondone
Oh yeah, sorry guys! Im assuming what Gabriel was referring to was that the code i post, needs to be placed between [ code=php ] & [ /code ] so that it looks like Gabriel's post?????

Code: Select all

 
<?php
 
include ('server.php');
 
$query = "select * from movies";
 
$result = mysql_query($query) or die(mysql_error());
 
$row = mysql_fetch_array($result) or die(mysql_error());
 
?>
 

Re: echoing an array

Posted: Fri May 22, 2009 2:49 am
by Mark Baker
What is the purpose of this line?
$row = mysql_fetch_array($result) or die(mysql_error());
You're fetching and discarding the first row returned from the database before going into your while loop

Re: echoing an array

Posted: Fri May 22, 2009 3:00 am
by dlusiondone
Legend! Thanks Mark! Much appreciated!