Jump to content

Pagination help


vitaminE

Recommended Posts

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.  :'(

Link to comment
Share on other sites

Hi,

Im not quite sure i understand how you are trying to organise your results.

 

Is is like this....

 

[flidIconMedium][fldTitle][fldLink]

 

As incubi1 says you will need a html table. If you show me how you want them displayed i dont mind nocking you up a table if your unsure.

 

Thanks

 

 

Link to comment
Share on other sites

http://netroxy.com/51274581336/search.htm This would be the page i am trying to make it like. This page is an example of the table I am trying to build. This is not the working result.

 

I am trying to categories my games to make users access the games easier. Lets say the user visits the website. User decides to click on Skills link (ex. www.blabla.com/gameslist.php?page=skills). As the user clicks Skills link, the pagination script displays results only for Skill games found in the database, hence finding them from the 'fldCategory' column, and displays the results horizontally and underneath each other. The same idea applies to searching for Action games '.php?page=action', or Adventure '.php?page=adventure' etc... etc...

Link to comment
Share on other sites

when i pageinate, that sounds odd for a start, anyway back on subject, i often use a select box to apply the filter, then grab it when form posts to itself (the pagenation page). but to keep the pagenation working you need to add an extra value to the string, so ?page=1&type=action.

 

what you are describing is a filter not pageination, but you can combine the 2 . pageination shows several pages of the same dataset, changing category changes the results.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.