This is my pagination with the number bar:
<?php
$page = $_GET['page'];
$category = $_GET['cat'];
$your_db = @ new mysqli("$hostname","$username", "$password");
if (mysqli_connect_errno())
{
echo 'ERROR!<br />'.mysqli_connect_errno()
.' - Not connected : '.mysqli_connect_error().'<br />';
die;
}
else
{
$db_connect = $your_db->select_db("database");
if (!$db_connect)
{
echo 'Error!';
die;
}
}
echo '<p>';
$query = "select distinct fldCategory from tablename order by fldCategory";
$result = $your_db->query($query);
$number_of_records = $result->num_rows;
for ($i = 0; $i < $number_of_records; $i++)
{
$row = $result->fetch_assoc();
echo '<a href="page_name.php?cat='.stripslashes($row['fldCategory']).'">';
echo stripslashes($row['fldCategory']);
echo '</a> / ';
}
echo '</p>';
if ($category)
{
$query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink
from tablename where fldCategory = '$category' order by fldCategory";
}
else
{
$query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink
from tablename order by fldCategory";
}
$result = $your_db->query($query);
$number_of_records = $result->num_rows;
$num_pages = $number_of_records / 7;
if (($number_of_records % 7) > 0 )
{
$num_pages++;
}
if (strlen($page) == 0)
{
$page = 0;
}
else
{
$page = $page * 7;
}
echo '<table border="1">';
$row_num = 1;
$result->data_seek($page);
for ($i = $page; $i < $number_of_records; $i++)
{
if ($row_num <= 7)
{
echo '<tr>';
for ($col_num = 0; $col_num < 5; $col_num++)
{
$row = $result->fetch_assoc();
echo '<td>';
show_image(stripslashes($row['fldIconMedium']),stripslashes($row['fldTitle']));
echo '<br />';
echo '<a href="'.stripslashes($row['fldLink']).'" target="_blank">';
echo stripslashes($row['fldTitle']);
echo '</a>';
echo '</td>';
}
$row_num++;
echo '</tr>';
}
else
{
break;
}
}
echo '</table>';
for ($j = 0; $j < $num_pages; $j++)
{
$page_link = $j + 1;
echo '<a href="page_name.php?page='.$j.'&cat='.$category.'">'.$page_link.'</a> ';
}
echo ' '.$number_of_records;
function show_image($image_name, $alt)
{
if (file_exists("path_to_images/$image_name"))
{
$dim_img = getimagesize('path_to_images/'.$image_name);
echo '<img src="path_to_images/'.$image_name.'" alt = '.$alt.' border=0 align="bottom"';
echo 'width = '. $dim_img[0] .' height = ' .$dim_img[1] . ' />';
}
else
echo 'NO IMAGE';
}
?>
To see it in action, here is the link to the 'skill games' section of the pagination script:
http://netroxy.com/games2.php?cat=skills
Ok here is the issue
1. As you can see, all the results displayed in the pagination script is correct, but what confuses me is the extra blank images that continue on in the table of the pagination table. I tried replacing the queries to see if the extra blank images would be removed like this:
$query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink
from tablename where fldCategory = '$category' and length(fldIconMedium) > 0
order by fldCategory";
}
else
{
$query = "select fldID, fldTitle, fldCategory, fldIconMedium, fldLink
where length(fldIconMedium) > 0 from tablename order by fldCategory";
So you see, I used 'length(fldIconMedium) > 0' making images less than 0 to see if the rest of the blank images would disappear from the cells in the table. This has not worked. Hence 'fldIconMedium' is the column for the images in the mysql database.
Visit the link and you'll see the extra blank images through the results. This also applies when search for other game categories, blank images appear and I cant remove those extra blank images from the table.