Hi guys,
My tables looks like this:
movieID movie_title
1 Seven Pounds
2 Tranformers
3 Angels & Demons
4 Bamboozelled
5 Waltz With Bashir
echoing an array
Moderator: General Moderators
-
dlusiondone
- Forum Newbie
- Posts: 4
- Joined: Fri May 22, 2009 12:55 am
Re: echoing an array
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.
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
Welcome to the forums. Please use the proper [ code=php ] ... [ /code ] tags.
What kind of SQL query are you using?
What kind of SQL query are you using?
Code: Select all
SELECT * FROM movies -- Anything like this?- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: echoing an array
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.
-
dlusiondone
- Forum Newbie
- Posts: 4
- Joined: Fri May 22, 2009 12:55 am
Re: echoing an array
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());
?>
Last edited by Benjamin on Fri May 22, 2009 9:45 am, edited 1 time in total.
Reason: Added [code=php] tags.
Reason: Added [code=php] tags.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: echoing an array
What is the purpose of this line?
You're fetching and discarding the first row returned from the database before going into your while loop$row = mysql_fetch_array($result) or die(mysql_error());
-
dlusiondone
- Forum Newbie
- Posts: 4
- Joined: Fri May 22, 2009 12:55 am
Re: echoing an array
Legend! Thanks Mark! Much appreciated!