Reputation: 3079
I have a database with a singe table, and two fields in said table, an ID number and filename. I use this DB to allow paging in a php script so I can show a set number of photos per page.
Here are the first 5 entires, and the code I use to sect from the databse:
1 - DSC_5480.jpg
2 - DSC_5483.jpg
3 - DSC_5487.jpg
4 - DSC_5488.jpg
5 - DSC_5489.jpg
And the code to print this in HTML:
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$start_from = ($page-1) * 25;
$data = mysql_query("SELECT * FROM $db_base.$db_tble LIMIT $start_from, 25")
or die(mysql_error());
$pictures = mysql_fetch_array( $data );
while($pictures = mysql_fetch_array( $data ))
{
echo "\t\t" . '<img src="images/' . $pictures['filename'] . '" alt="' . $pictures['filename'] . '" />' . "\n";
}
The problem I'm running into is the first entry in the table is skipped as you can see from the HTML code.
<img src="images/DSC_5483.jpg" alt="DSC_5483.jpg" />
<img src="images/DSC_5487.jpg" alt="DSC_5487.jpg" />
<img src="images/DSC_5488.jpg" alt="DSC_5488.jpg" />
<img src="images/DSC_5489.jpg" alt="DSC_5489.jpg" />
<img src="images/DSC_5491.jpg" alt="DSC_5491.jpg" />
So my question is what am I doing wrong to not allow the first entry to be displayed?
Upvotes: 1
Views: 219
Reputation: 94645
Take a look at code-snippet, you have write twice this statement : $pictures = mysql_fetch_array( $data );
It should be,
$data = mysql_query("SELECT * FROM $db_base.$db_tble LIMIT $start_from, 25")
or die(mysql_error());
while($pictures = mysql_fetch_array( $data ))
{
echo "\t\t" . '<img src="images/' . $pictures['filename'] . '" alt="' . $pictures['filename'] . '" />' . "\n";
}
Upvotes: 7