Nas[wD] Posted February 19, 2010 Share Posted February 19, 2010 So I have this code im working on where it's ment to display seperate pages having 20 logs each I'm having SOOOOOOOOO much trouble with it... it's supposed to work! >,< I get the right amount of Pages 1,2,3,4, but when I click on them it doesn't show up right =( http://www.clan-wd.com/test.php <?php include "config.php"; if($page == NULL) { $page = 0; } else { $page = $page - 1; } global $myrow; extract($myrow); if($p == "") { echo "<table width='100%' border='3'>"; // Counting Codes ######### $result = @mysql_query("SELECT COUNT(*) FROM logs"); $count = mysql_fetch_array($result); $count = $count[0]; $num_pages = ($count / 20) + 1; $limit = 20 + $startNum * 20; $i = 0; $result = @mysql_query("SELECT * FROM logs ORDER BY id DESC"); while(($row = mysql_fetch_array($result)) && $i <= $limit) { extract($row); if($i >= ($startNum * 20)) { echo " <tr><td><b>$id - $logName</b> $date</td></tr> "; } $i++; } echo " </table> <p align=left><b>Page:</b> "; for($i = 1; $i <= $num_pages; $i++) { echo "<a href=test.php?page=$i>$i</a>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/192607-need-helpw-page-1234-function/ Share on other sites More sharing options...
Nas[wD] Posted February 19, 2010 Author Share Posted February 19, 2010 god this suckkss soo much, i'm trying to many different things but the pages are wack lol. the code's too complicating Link to comment https://forums.phpfreaks.com/topic/192607-need-helpw-page-1234-function/#findComment-1014935 Share on other sites More sharing options...
piyush23424 Posted February 19, 2010 Share Posted February 19, 2010 Hi, you may get syntax error but the logic is correct <?php include "config.php"; $resultsPerPage = 10; if(isset($_GET['p'])){ $currentPage = $_GET['p']; } else{ $currentPage = 1; } $limit = $currentPage-1; $limit =$limit*$resultsPerPage; global $myrow; extract($myrow); if($p == "") { echo "<table width='100%' border='3'>"; // Counting Codes ######### $result = @mysql_query("SELECT COUNT(*) FROM logs"); $count = mysql_fetch_array($result); $totalrecords = $count[0];//assuming $count[0] has total no of records /*$num_pages = ($count / 20) + 1; $limit = 20 + $startNum * 20; $i = 0; */ $query = "SELECT * FROM logs ORDER BY id DESC limit $limit,$resultsPerPage" $result = @mysql_query($query); while($row = mysql_fetch_array($result)) { extract($row); if($i >= ($startNum * 20)) { echo " <tr><td><b>$id - $logName</b> $date</td></tr> "; } $i++; } echo " </table> <p align=left><b>Page:</b> "; echo $pages = ceil($totalrecords/$resultsPerPage); $pagination=''; for($page=1;$page<=$pages;++$page) { $pagination .= "<a style='border:1px solid #CCCCCC;display:block;float:left;font-size:0.75em;line-height:normal;margin-left:2px;padding:2px 5px;' href='http://localhost/test/test8.php?p=$page'>$page</a>"; } echo "<br/>"; if($totalrecords > $resultsPerPage) { echo $pagination; } } ?> [\code] Here is the correctly working code on my system for pagination, you can make change according to my code if you get error with the above code [code] <?php $resultsPerPage = 10; if(isset($_GET['p'])){ $currentPage = $_GET['p']; } else{ $currentPage = 1; } $limit = $currentPage-1; $limit =$limit*$resultsPerPage; mysql_connect('localhost','root','projects'); mysql_select_db('codeigniter'); $count = mysql_query("select * from user_pdf_records"); echo $totalrecords = mysql_num_rows($count); echo $q = "select * from user_pdf_records limit $limit,$resultsPerPage"; echo "<br/>"; $res = mysql_query($q); echo "<div style='width:500px;'>"; $i = 1; while($row = mysql_fetch_array($res)){ if($i == 1){ ?> <div style="background-color:#999;"><?=$row['user_record_name']?></div> <?php ++$i; } else{ ?> <div style="background-color:#666;"><?=$row['user_record_name']?></div> <?php $i = 1; } } echo "</div>"; echo "<br/>"; echo $pages = ceil($totalrecords/$resultsPerPage); $pagination=''; for($page=1;$page<=$pages;++$page) { $pagination .= " <a style='border:1px solid #CCCCCC;display:block;float:left;font-size:0.75em;line-height:normal;margin-left:2px;padding:2px 5px;' href='http://localhost/test/test8.php?p=$page'>$page</a>"; } echo "<br/>"; if($totalrecords > $resultsPerPage){ echo $pagination; } /* for($i=0;$i<=20;$i++){ $value = "hello".$i; echo $sql = "insert into user_pdf_records(user_record_name) values('$value')"; mysql_query($sql); }*/ ?> Link to comment https://forums.phpfreaks.com/topic/192607-need-helpw-page-1234-function/#findComment-1014962 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.