taz321 Posted February 9, 2008 Share Posted February 9, 2008 Hi I am new to pagination but have a general idea on what it does. Basically i have a helpdesk system and people would submit tickets for any technical issues they have. Now i have a page where the list of tickets go on forever (about 60 tickets). How would i go about making sure it displays only the first 10 results, and then have another 10 results showing on another page (if you know what i mean). Basically heres my code so far, which displays the tickets (the data in the database) while($row= mysql_fetch_array($result)){?></td> <td height="35"><div align="center" class="style7"><?php echo $row['formID'];?></div></td> <td height="35"><div align="center" class="style7"><?php echo $row['issuetitle'];?></div></td> <td height="35"><div align="center" class="style7"><?php echo $row['datesubmitted'];?></div></td> <td height="35"><div align="center" class="style7"><?php echo $row['systemaffected'];?></div></td> <td height="35"><div align="center"><span class="style7"><?php echo $row['prioritylevel'];?></span></div></td> <td height="35"><div align="center"><span class="style7"><?php echo $row['teamname'];?></span></div></td> <td height="35"><div align="center" class="style7"><?php echo $row['employeeID'];?></div></td> How would i go about doing pagination ? Any help would be appreciated Thanks Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/ Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 Here are some tutorials: http://php.about.com/od/phpwithmysql/ss/php_pagination.htm http://www.tonymarston.net/php-mysql/pagination.html http://www.sitepoint.com/article/perfect-php-pagination http://www.webpronews.com/expertarticles/2006/06/20/php-pagination-with-mysql http://www.tutorialized.com/tutorial/Pagination-with-PHP/6925 Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462669 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 Iv had a go, but doest seem to be working, any ideas ? <?php $query1 = mysql_query("SELECT * FROM form LIMIT $startrow, 10")or die (mysql_error()); if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { $startrow = 0; } else { $startrow = (int)$_GET['startrow']; } ?> Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462673 Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 MOre like <?php if (!isset($_GET['startrow']) or !is_numeric($_GET['startrow'])) { $startrow = 0; } else { $startrow = (int)$_GET['startrow']; } $query1 = mysql_query("SELECT * FROM form LIMIT $startrow, 10")or die (mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462674 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 Not quite sure what else to do, i have inputted 12 rows of data in the database and i only want the first 10 to display, but on my screen after implementing the above code, all 12 are still shown. Any ideas Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462686 Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 Not quite sure what else to do, i have inputted 12 rows of data in the database and i only want the first 10 to display, but on my screen after implementing the above code, all 12 are still shown. Any ideas Thats not a pagination, a pagination is much longer written. Try the PHP.about one Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462691 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 longer written as in there is much more code than i have currently ?? Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462696 Share on other sites More sharing options...
phpSensei Posted February 9, 2008 Share Posted February 9, 2008 http://php.about.com/od/phpwithmysql/ss/php_pagination.htm try that one Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462697 Share on other sites More sharing options...
alexinjamestown Posted February 9, 2008 Share Posted February 9, 2008 Hi there, here's an excellent script, but you have to put it in different parts or it won't run. I really like this script, and then if you want to swap background colors there's some more code. Let me know if you want that, but here's pagination first. The first part that I'm cutting is after establishing connection to MySQL require_once ('./mysql_connect.php'); // Connect to the database. // Number of records to show per page: $display = 11; // Determine how many pages there are. if (isset($_GET['np'])) { // Already been determined. $num_pages = $_GET['np']; } else { // Need to determine. // Count the number of records $query = "SELECT COUNT(*) FROM uploads ORDER BY date_entered DESC"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); $num_records = $row[0]; // Calculate the number of pages. if ($num_records > $display) { // More than 1 page. $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } // End of np IF. $first = TRUE; // Initialize the variable. if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Query the database. -------------------------------------------- The second part starts after you close the connection to the db // Make the links to other pages, if necessary. if ($num_pages > 1) { echo '<br /><p> <p>'; // Determine what page the script is on. $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button. if ($current_page != 1) { echo '<a href="view_files_tables.php?s=' . ($start - $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Previous</a> '; } // Make all the numbered pages. for ($i = 1; $i <= $num_pages; $i++) { if ($i != $current_page) { echo '<a href="view_files_tables.php?s=' . (($display * ($i - 1))) . '&np=' . $num_pages . '&sort=' . $sort .'">' . $i . '</a> '; } else { echo $i . ' '; } } // If it's not the last page, make a Next button. if ($current_page != $num_pages) { echo '<a href="view_files_tables.php?s=' . ($start + $display) . '&np=' . $num_pages . '&sort=' . $sort .'">Next</a>'; } echo '</p>'; } // End of links section. Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462704 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 That is a bit too confusing for me...... I have had a go and this is what iv got, but I'm quite confused, would it be possible to get some example code, or it shown to me in bitesize, i get confused in the fact that people write php code in different ways ? Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462711 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 you were abit too fast for me lol, im jus reviewing ur code now Thanks Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462713 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 but you have to put it in different parts or it won't run What do you mean in different parts ? Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462719 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 Am i along the right lines here - this is the code so far...(you may see there is some other code, but that is for other purposes which hopefully shudnt interrupt with the current code. <?php session_start(); if (isset($_SESSION['username']) == false){ header("Location:login.php"); exit(); } require "connect.php"; $sortby = $_GET['var']; $query = "select * from form ORDER by $sortby"; $result = mysql_query($query, $connection) or die ("MySQL Error: ".mysql_error()); $display = 6; if (!isset($_GET['np']; { $num_pages = $_GET['np']; } else { $query1 = "SELECT COUNT(*) FROM form"; $result1 = @mysql_query ($query1); $row = mysql_fetch_array ($result1, MYSQL_NUM); $num_records = $row[0]; f ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } $first = TRUE; if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } ?> Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462725 Share on other sites More sharing options...
alexinjamestown Posted February 9, 2008 Share Posted February 9, 2008 g'day Taz... It's quite simple really. You just need to put the code where I had mentioned. Would you like to see my entire script? If you want, I have an email address that I use for this sort of stuff, and I can show you the whole script and how it works if you want, but it would be sooo much easier if you were to email me, especially that my database is for yacht crew and I don't feel like posting it in a public forum but am totally happy giving you my yahoo address. It's [email protected] Cheers, Alex Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462737 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 Yeh cheers mate, il email you now, also are you on MSN ? Thanks. Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462741 Share on other sites More sharing options...
alexinjamestown Posted February 9, 2008 Share Posted February 9, 2008 I'm on msn... I'll give you my screen name when we email each other Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462742 Share on other sites More sharing options...
taz321 Posted February 9, 2008 Author Share Posted February 9, 2008 Just emailed you now mate, cheers Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462745 Share on other sites More sharing options...
alexinjamestown Posted February 9, 2008 Share Posted February 9, 2008 This site keeps on crashing on me. Yes, I have msn. When you email I will get my screen name to you on that. Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462747 Share on other sites More sharing options...
alexinjamestown Posted February 9, 2008 Share Posted February 9, 2008 hmm... I haven't received it yet. it's [email protected] in case I had a typo... Link to comment https://forums.phpfreaks.com/topic/90238-inocorporating-pagination/#findComment-462751 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.