ted_chou12 Posted December 27, 2006 Share Posted December 27, 2006 I sort of have the idea, but i dont know how to put it into practical, what I believe will do is this:by using the while fuction as well as the modules function, so when the remainder equal to one, then the list goes to another page for the new 10 results, and goes on until when the modules cannot reach 1, it will display the remainder of the ten pages in the last page. But what I am not sure is how to add pages, can anyone help me out with this?ThanksTed Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/ Share on other sites More sharing options...
obsidian Posted December 27, 2006 Share Posted December 27, 2006 Check out the [url=http://www.phpfreaks.com]main PHPFreaks site[/url] for tutorials on "Page Numbering" or "Pagination." Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148443 Share on other sites More sharing options...
ted_chou12 Posted December 27, 2006 Author Share Posted December 27, 2006 sorry, but the link doesnt seem to work for me, everything turns blank white in the page, I cant see anything, what is the problem? Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148449 Share on other sites More sharing options...
obsidian Posted December 27, 2006 Share Posted December 27, 2006 Don't know, but [url=http://www.phpfreaks.com/tutorials/73/0.php]here is a direct link[/url] to one of the best Page Numbering tutorials. Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148460 Share on other sites More sharing options...
ted_chou12 Posted December 27, 2006 Author Share Posted December 27, 2006 nope is white as well... can you paste the whole tutorial please?? :)I really need it and I cant find anything about it on google, everything comes up in the search in irrelavant.Thanks for your kindness.Ted Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148462 Share on other sites More sharing options...
ted_chou12 Posted December 27, 2006 Author Share Posted December 27, 2006 how about a zip file of the html pages? or send it to my email? anything will do... Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148466 Share on other sites More sharing options...
craygo Posted December 27, 2006 Share Posted December 27, 2006 here is what I use. Change it up to fit your database structure[code]<?php// connect to mysql below// Set how many rows to display on each page$limit = 200;// Query the database to get the total number of rows$query_count = "SELECT * FROM tablename"; $result_count = mysql_query($query_count) or die (mysql_error()); $totalrows = mysql_num_rows($result_count); if(isset($_GET['page'])){ // Checks if the $page variable is empty (not set) $page = $_GET['page']; // If it is empty, we're on page 1 } else { $page = 1; }// Set the start value$startvalue = $page * $limit - ($limit);// Query the database and set the start row and limit$sql = "SELECT * FROM table_name LIMIT $startvalue, $limit"; $res = mysql_query($sql) or die (mysql_error()); echo "<table border=1 width=450 align=center> <tr> <td width=100>field1 title</td> <td width=175>field2 title</td> <td width=175>field3 title</td> </tr>";// Do a quick check to see if there are any records to display if(mysql_num_rows($res) == 0){ echo "<tr> <td colspan=3 align=center>No Records found!!</td> </tr>"; }// Start loop through recordswhile ($r = mysql_fetch_array($res)){// Echo out the records with wordwrap, remove if you likeecho "<tr>\n";echo "<td width=100>" . wordwrap($r['field1'], 2, " ", 1)."</td>\n";echo "<td width=175>" . wordwrap ($r['field2'], 10, " ", 1)."</td>\n";echo "<td width=175>" . wordwrap($r['field3'], 10, " ", 1)."</td>\n";echo "</tr>\n";}// Close the tableecho "</table>";// Start links for pagesecho "<p align=center>";// Sets link for previous 25 and return to page 1 if($page != 1){ $pageprev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=1\"><<</a> "; echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$pageprev\">PREV </a> "; }else{ echo "PREV "; }// Find out the total number of pages depending on the limit set $numofpages = $totalrows / $limit; $totalpages = round($numofpages);// Loop thru all the pages and echo out the links for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo "[".$i."] "; }else{ echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } }// Check for straglers after the limit blocks if(($totalrows % $limit) != 0){ if($i == $page){ echo "[".$i."] "; }else{ echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } }// Print out the Next 25 and Goto Last page links if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$pagenext\">NEXT </a> "; echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$totalpages\">>></a> "; }else{ echo("NEXT"); }echo "</p>";// Free resultsmysql_free_result($res);// Close mysql connectionmysql_close($mysql_conn);?>[/code] Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148474 Share on other sites More sharing options...
Barand Posted December 27, 2006 Share Posted December 27, 2006 Check your browser settings. The link is OK for the rest of us. Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148479 Share on other sites More sharing options...
ted_chou12 Posted December 27, 2006 Author Share Posted December 27, 2006 thanks craygo!But I still really wish to see the tutorial as well...Ted Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148531 Share on other sites More sharing options...
Psycho Posted December 27, 2006 Share Posted December 27, 2006 Since the links don't seem to work for you:1. Point your browser to http://www.phpfreaks.com2. Click the PHP Tutorials link in the middle, right of the page3. Click the "Page Numbering / Pagination" link on the Tutorials page4. Click the "Page Numbering With PHP And MySQL Results" tutorial (which is the one Barand suggested) Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148534 Share on other sites More sharing options...
ted_chou12 Posted December 28, 2006 Author Share Posted December 28, 2006 Thanks mjdamato, but I cannot access all of the pages before the forum folder, after the "http://www.phpfreaks.com/forums/" <<<before the folders of forums, all the pages turn out blank white for me, and I dont know why, I tried to add the http://www.phpfreaks.com link as a safe link as a property of IE but it still wouldnt work... btw, i first got here through google, so i didn't get through the main page at all...Thanks anyway, really appreciated it :DTed Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148556 Share on other sites More sharing options...
craygo Posted December 28, 2006 Share Posted December 28, 2006 I left comments all over the script so at least you can see what each part doesRay Link to comment https://forums.phpfreaks.com/topic/31985-display-mysql-results-in-10-per-page/#findComment-148720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.