Pagination number bar and Image problem

Here is the pagination code with 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("your_data_base_name"); 
    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>&nbsp;/&nbsp;'; 
} 
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>&nbsp;'; 
} 
echo '&nbsp;'.$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 a couple of issues:

  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 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’ for the queries to see if the extra images in the table would disappear. This has not worked.

  1. I can’t hyperlink the images. The Titles underneath the images work and they direct to their games, but the Images I can not hyperlink to the games. I tried putting ‘’.stripslashes($row[‘fldLink’]).‘’ into the ahref for the images, but it doesn’t seem to work like the Titles do.

  2. I’m not sure how to add a ‘Next’ and ‘Previous’ button to the number bar in the pagination above. Can someone tell me if there is anything wrong with the number bar script?