Hello friends. I have a pagination script and there are 3 issues I cant seem to figure out. Here is the code:
<?php
// page_name.php
$page = $_GET['page'];
//some code
$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 CONNECT DATA BASE';
die;
}
}
$query = "select fldIconMedium, fldTitle, fldLink from games";
//$result = $db_connect->query($query);
$result = $your_db->query($query);
$number_of_records = $result->num_rows;
$num_pages = $number_of_records / 16;
if (($number_of_records % 16) > 0 )
{
$num_pages++;
}
if (strlen($page) == 0)
{
$page = 0;
}
else
{
$page = $page * 16;
}
$br = 1;
$result->data_seek($page);
for ($i = $page; $i < $number_of_records; $i++)
{
//$row = $result->fetch_array();
$row = $result->fetch_assoc();
if ($br <= 16)
{
echo '<b>'.stripslashes($row['fldIconMedium']).' </b>';
echo stripslashes($row['fldTitle']).' ';
echo '<b>'.stripslashes($row['fldLink']).'</b><br />';
$br++;
}
else
{
break;
}
}
for ($j = 0; $j < $num_pages; $j++)
{
$page_link = $j + 1;
echo '<a href="games2.php?page='.$j.'">'.$page_link.'</a>';
}
echo ' '.$number_of_records;
?>
Here is a database I am using:
|fldID| |fldTitle| | fldCategory | fldIconMedium | | fldLink |
2415 Krusty Fun House Skills krusty.jpg games.php?id=2415
2415 Krusty Fun House Skills krusty.jpg games.php?id=2415
2415 Krusty Fun House Skills krusty.jpg games.php?id=2415
2415 Krusty Fun House Adventure krusty.jpg games.php?id=2415
2415 Krusty Fun House Adventure krusty.jpg games.php?id=2415
2415 Krusty Fun House Adventure krusty.jpg games.php?id=2415
2415 Krusty Fun House Action krusty.jpg games.php?id=2415
2415 Krusty Fun House Action krusty.jpg games.php?id=2415
2415 Krusty Fun House Action krusty.jpg games.php?id=2415
I have a couple of issues as I am still a noob learning PHP.
=====================================
1. I have no idea how to add a 'Previous' and 'Next' button to the pagination number bar.
2. My results are displayed vertical and I can't make my results display in a horizontal view. 5 results going from left to right and results from top to bottom Basically 5 x 7 table
3. I have an issue with categorizing my games in my pagination table. I have multiple categories like Action, Skills, Arcade, Skills, Mind, Shooter in my database. For example, the pagination script above creates the link to be like this '.php?page=1', when in fact I want the script to search for categories games, example '.php?page=skills', '.php?page=action', '.php?page=adventure' etc..., linking them to the 'fldCategory' column which has the list of the category names of games, and then fetching all the rows of that particular game category and be displayed in the 5 x 7 table. For each result, it would have the Image Icon (fldIconMedium), the Title (fldTitle) under it, and both of them hyper linked to their links from the 'fldLinks' column.
I would really appreciate the help. It has been 2 weeks and I'm very frustrated that I can't figure the 3 points out. :'(