vitaminE Posted May 5, 2011 Share Posted May 5, 2011 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. :'( Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/ Share on other sites More sharing options...
perky416 Posted May 5, 2011 Share Posted May 5, 2011 Hi mate, Take a look at this: http://www.youtube.com/watch?v=wC0uc_TkdR0 A very good tutorial on pagination. I know it covers the prev and next buttons, im not too sure if it can help with your other 2 problems though. You should check it out. Hope it helps. Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211104 Share on other sites More sharing options...
vitaminE Posted May 5, 2011 Author Share Posted May 5, 2011 Hi Perky thanks for the link. I'll take a look at it. I'd like to know if its difficult displaying results horizontally? Would anybody else help me with the last 2 points? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211105 Share on other sites More sharing options...
incubi1 Posted May 5, 2011 Share Posted May 5, 2011 Here's another good howto http://onlamp.com/pub/a/php/2000/11/02/next_previous.html Also on how the results data is displayed, use an HTML table for doing that will allow you do pick what cell the data goes in. Lee Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211111 Share on other sites More sharing options...
perky416 Posted May 5, 2011 Share Posted May 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211113 Share on other sites More sharing options...
vitaminE Posted May 5, 2011 Author Share Posted May 5, 2011 Thank you so much! I have my own page here, http://netroxy.com/51274581336/search.htm You can see its a very neat table displaying the results horizontally. the Images come from 'fldIconMedium' column, titles come from 'fldTitle' column, and the links come from 'fldLink' column to hyperlink each results to their games. Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211135 Share on other sites More sharing options...
vitaminE Posted May 5, 2011 Author Share Posted May 5, 2011 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... Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211168 Share on other sites More sharing options...
spiderwell Posted May 6, 2011 Share Posted May 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235634-pagination-help/#findComment-1211255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.