PHP - Issue With Pagination
I want to add the result of a query to another table but every time i click on it, it only saves the first record, please help me check out my code
thanks
<?php
// hide errors error_reporting(0); /* Include the Pear::Pager file */ include('mysql_connect.php'); //include of db config file include ('paginate.php'); //include of paginat page $per_page = 5; // number of results to show per page $result = mysql_query("SELECT * FROM users"); $total_results = mysql_num_rows($result); $row=mysql_fetch_assoc($result); $total_pages = ceil($total_results / $per_page);//total pages we going to have //while ($row=mysql_fetch_assoc($result)){ //-------------if page is setcheck------------------// if (isset($_GET['page'])) { $show_page = $_GET['page']; //it will telles the current page if ($show_page > 0 && $show_page <= $total_pages) { $start = ($show_page - 1) * $per_page; $end = $start + $per_page; } else { // error - show first set of results $start = 0; $end = $per_page; } } else { // if page isn't set, show first set of results $start = 0; $end = $per_page; } // display pagination $page = intval($_GET['page']); $tpages=$total_pages; if ($page <= 0) $page = 1; ?> <?php // hide errors error_reporting(0); $reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages; echo '<div class="pagination"><ul>'; if ($total_pages > 1) { echo paginate($reload, $show_page, $total_pages); } echo "</ul></div>"; // display data in table echo "<table class='table table-bordered'>"; echo "<thead><tr><th>First Name</th> <th>Last Name</th> <th>Department</th> <th>Status</th></tr></thead>"; // loop through results of database query, displaying them in the table for ($i = $start; $i < $end; $i++) { // make sure that PHP doesn't try to show results that don't exist if ($i == $total_results) { break; } // echo out the contents of each row into a table echo "<tr> "; echo '<td>' . mysql_result($result, $i, 'firstname') . '</td>'; echo '<td>' . mysql_result($result, $i, 'lastname') . '</td>'; echo '<td>' . mysql_result($result, $i, 'department') . '</td>'; echo ' <td><a href="add_team.php?id='.$row['id'].'"> Add Team Member </a></td>'; } echo "</tr>"; // } // close table> echo "</table>"; // pagination ?> Similar TutorialsGreetings All! New to PHP, and trying to learn as much as I can as quickly as I can for a client. I have been following some of Tutorials i understand most of it, but I still don't understand a few of the functions. Anyways, here is my problem. I am trying to combined the two tutorials (Pagination and Search Internal) but I seem to have myself in a loop... Code is as follows: Code: [Select] <?php $connect = mysql_connect("localhost","root","~~~~"); $db = mysql_select_db("~~~"); $button = $_GET['submit']; $search = $_GET['search']; if ($button) { if (strlen($search)<=0) echo "Please enter a keyword"; else { //explode our search terms $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "keywords LIKE '%$search_each%' OR vid_state LIKE '%$search_each%' OR users LIKE '%$search_each%' OR title LIKE '%$search_each%'"; else $construct .= " OR keywords LIKE '%$search_each%' OR vid_state LIKE '%$search_each%' OR users LIKE '%$search_each%' OR title LIKE '%$search_each%'"; } //eco out construct $construct = "SELECT * FROM video_url WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); //max display per page $per_page = 3; //get start variable $start = $_GET['start']; //count records $record_count = $foundnum; //count max pages $max_pages = $record_count / $per_page; //may come out as decimal $pagenumbers = intval($max_pages) + 1; if (!$start) $start = 0; //setup previous and next variables $prev = $start - $per_page; $next = $start + $per_page; //show prev button if (!($start<=0)) echo "<a href='searchvideos.php?start=$prev'><img src='../images/texts/previous.png' border='0'></a> "; //show next button if (!($start>=$record_count-$per_page)) echo " <a href='searchvideos.php?start=$next'><img src='../images/texts/next.png' border='0'></a>"; //set variable for first page $i=1; for ($y=0;$y<$record_count;$y=$y+$per_page) { if($start!=$y) echo " <a href='searchvideos.php?start=$y'><span class='searchtext'>$i</span></a>"; else echo " <a href='searchvideos.php?start=$y'><span class='searchtext'> <font size='+1'><b>$i</b></font></span></a>"; $i++; } //show page numbers echo " / <font color='#FF6600' size='-1'>$pagenumbers</font> </td> <td align='right' width='50%'> <form action='../pages/searchvideos.php' method='get'> <span class='searchtext'>Search Videos</span> <input name='search' type='text' value='by Keywords, Title, Name, or State' size='35' /><input type='submit' name='submit' value='search' /> </form> </td> </tr> </table> </div> <br /><br /><div class='videotitle'><span class='createtext'> Videos </span></div> <br /><br />"; if ($foundnum==0) echo "No results found."; else { echo "$foundnum results found!<br><br>"; $query = mysql_query("SELECT * FROM video_url ORDER BY RAND() LIMIT $start, $per_page"); while($row = mysql_fetch_array($query)) //while ($numrows = mysql_fetch_assoc($run)) { $title = $row['title']; $url = $row['url']; $state = $row['vid_state']; $users = $row['users']; echo " <table bgcolor='#191919' cellpadding='0' cellspacing='0' background='../images/videobgs.png' align='center'> <tr> <td width='10px'></td> <td width='440px' height='370px' rowspan='6'> $url </td> <td width='340px' align='left'> <span class='createtext'>$title</span><hr /> $users<br /> $state </td> <td width='5px'></td> </tr> <tr><td> </td></tr> <tr><td> </td></tr> </table><br />"; } } } } ?> I know my code is dirty, and I have a lot to learn, and that I should probably be doing this a different way, but please try to correct the way I have it. Anyways..first page loads great, the search works great, the pagination works as it should (correct pages, correct page numbers, etc.). However, once I click on the "next" or the next "number" the next page is blank because the very first if statement throws a kink in my code... if ($button) - when continuing to the next page, a "$button" is not pressed and therefore doesn't continue the code, leaving the page blank. Any clues on how to fix this? I have tried combining the two in many different ways, this is the best i got so far... Thanks in advance, Phantaz I have a basic pagination class, I have used on several pages of a site I am working on. It works fine on 3 of the pages, but when I try to use it on any other pages, or even a new blank page I wrote, it does not work. class Pagination { public $current_page; public $per_page; public $total_count; public function __construct($page=1, $per_page=20, $total_count=0) { $this->current_page = (int)$page; $this->per_page = (int)$per_page; $this->total_count = (int)$total_count; } public function offset(){ return ($this->current_page - 1) * $this->per_page; } public function total_pages(){ return ceil($this->total_count/$this->per_page); } public function previous_page(){ return $this->current_page - 1; } public function next_page(){ return $this->current_page + 1; } public function has_prev_page(){ return $this->previous_page() >= 1 ? true : false; } public function has_next_page(){ return $this->next_page() <= $this->total_pages() ? true : false; } That is the pagination class, and this is the code I use to call it, along with some debugging information I am using. if(isset($_GET['order'])){ $order = $_GET['order']; } else { $order = "id"; } if(isset($_GET['orderby'])){ $order_by = $_GET['orderby']; } else { $order_by = "ASC"; } $page = !empty($_GET['page']) ? (int)$_GET['page'] : 1; $per_page = 2; $sql = mysql_query("SELECT * FROM orders WHERE customerid = 4"); $result = mysql_fetch_array($sql); $total_count = mysql_num_rows($sql); //$total_count = Order::count_by_cust(4); $pagination = new Pagination($page, $per_page, $total_count); $sql = "SELECT * FROM orders WHERE customerid = 4 ORDER BY {$order} {$order_by} "; $sql .= "LIMIT {$per_page} "; $sql .= "OFFSET {$pagination->offset()}"; $orders = Order::find_by_sql($sql); echo "Page:" . $page . "<br />PerPage:" . $per_page . "<br />Total:" . $total_count . "<br />Total Pages:" . $pagination->total_pages(); ?> SOME FOREACH INFORMATION HERE <?php echo "Has Prev Page:" . $pagination->has_prev_page() . "<br />"; echo "Total Pages:" . $pagination->total_pages() . "<br />"; echo "Has Next Page:" . $pagination->has_next_page() . "<br />"; ?> <div id="pagination" style="clear: both; text-align: center;"> <?php if ($pagination->total_pages() > 1){ if ($pagination->has_prev_page() == 1){ echo "<a href=\"orders.php?search&uid={$order->customerid}&order={$order}&orderby={$order_by}&page="; echo $pagination->previous_page(); echo "\">« Previous</a>"; } for($i=1; $i<=$pagination->total_pages(); $i++){ if($i == $page){ echo " <span class=\"selected\">{$i}</span> "; } else { echo " <a href=\"orders.php?search&uid={$order->customerid}&order={$order}&orderby={$order_by}&page={$i}\">{$i}</a> "; } } if ($pagination->has_next_page() == 1){ echo "<a href=\"orders.php?search&uid=" . $order->customerid . "&order=" . $order . "&orderby=" . $order_by . "&page="; echo $pagination->next_page(); echo "\">Next »</a>"; } } ?> </div> The customer ID is dynamic, but for debugging sake I am using the customer ID of 4. The output of the page has the following informaton: Page:1 PerPage:2 Total:15 Total Pages:8 Has Prev Page: Total Pages:8 Has Next Page:1 So i know all the variables are right, the problem is, it only prints a bold "1". Thats all, no numbers, or Next Page option. However i use the EXACT same code in another couple pages, and it works fine, but with this current page and a few others. It does not work. I have also tryed extracting just this information into a blank file to just get the page numbers, taking out all the pages other code, and it still only gives me "1". Any ideas? <?php error_reporting(0); $servername = "localhost"; $username = "user"; $password = "pw"; $dbname = "news"; $datatable = "ttrss_user_labels2"; // MySQL table name $datatable2 = "ttrss_entries"; $results_per_page = 10; // number of results per page // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?> <?php if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $results_per_page; $sql = "SELECT * FROM ".$datatable2.", ".$datatable." WHERE article_id = id ORDER BY date_entered DESC LIMIT $start_from, ".$results_per_page; $rs_result = $conn->query($sql); ?> <?php while($row = $rs_result->fetch_assoc()) { ?> <?php $title = preg_replace('/[^(\x20-\x7F)]*/','', $row['title']); $content = preg_replace('/[^(\x20-\x7F)]*/','', $row['content']); ?> <table id="news" border="1" cellpadding="1" class="mx-auto col-xs-12 col-sm-12 col-md-12 col-lg-12"> <tr class="wrap"><td class="rounded-lg shadow curved"> <?php echo '<div charset="UTF-16" class ="text-center" style ="font:14px/18px Arial,tahoma,sans-serif top:5px">', $title, '<hr class=mx-auto></div>'; ?> <?php echo '<div charset="UTF-16" class ="text-center" style ="font:11px/21px Arial,tahoma,sans-serif">', $content, ' ', '<a href= "' . $row['link'] . '" target=_blank>Read More</a>', '</div>'; ?> <div style ="font:9px/15px Arial,tahoma,sans-serif" class="text-right"><? echo date('F j, Y g:i a', strtotime($row["date_entered"])) ?><br></div> <? echo '</td></tr></table><br><br>'; ?> <?php }; ?> <!--Grid row--> <div class="row d-flex justify-content-center"> <!--Grid column--> <div class="top_menu col-xs-12 col-sm-12 col-md-12 col-lg-12"> <div class="container"> <div class="row"><div class="col-md-9"> <ul class="pagination pagination-sm pagination-centered"> <?php $sql = "SELECT COUNT(ID) AS total FROM ".$datatable2; $result = $conn->query($sql); $row = $result->fetch_assoc(); $total_pages = ceil($row["total"] / $results_per_page); // calculate total pages with results $firstPage = 0; // or 1, depending on your implementation $currentPage = (int)$_GET['page']; if ($currentpage != $total_pages) { $nextpage = $currentPage + 1; $prevpage = $currentPage - 1; echo "<li><a href='index.php?page=$prevpage'><<</a></li> "; // for ($i=1; $i<=$total_pages; $i++) { // print links for all pages for($i = $page + 1; $i <= min($page + 4, $total_pages); $i++) { echo "<li><a href='index.php?page=".$i."'"; if ($i==$page) echo " class='curPage'"; echo ">".$i."</a></li> "; }; echo "<li><a href='index.php?page=$nextpage'>>></a></li> "; // echo "<li><a href='index.php?page=$total_pages'>last</a></li></u><br><br>"; } ?> </div></div></div><div class="clearfix">
Hi fellow PHP coders, I have gotten stuck with this code a bit as I was trying to build my first pagination script. I am getting only the 10 latest results from the database on all result pages. I am not sure what exactly I did wrong in this code to make it show all the results database has to offer spanning across pages at a rate of 10 per page from most current first to the oldest. Anyone have any ideas what I am doing wrong here? Any suggestions are much appreciated.
can anybody tell me what's wrong with my query ? $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC"; I am using this in while loop with ps_pagination class but getting 2 records for same set of files. in other words its running while loop 2 time complete code is here... $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel FROM ibwf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC"; $pager = new PS_Pagination($conn, $filesa, 9, 5, $albumid, $sortid, $sub, $selectalbum3[uid], $title, $collective); $results = $pager->paginate(); while($files=mysql_fetch_array($results)) { // Blah Blah } Output is something like this 1. song 1 2. song 2 3. song 3 4. song 4 1. song 1 2. song 2 3. song 3 4. song 4 Thanks is advance Sorry to bug yalls with yet another problem, but I tried applying pagination to the page I use to display the news on my website, which is stored within mysql, and I'm having major issues. Here's the code below for both the pagination and getting the news out of the database to display. Not sure what's going on here. I tested the script and it does everything fine except it doesn't display the information stored within the database. Go here to see for yourself: http://www.djsmiley.net/index.php Code: [Select] <?php /* Place code to connect to your DB here. */ include('cms/news/dbconnect.php'); // include your code to connect to DB. $tbl_name="mynews"; //your table name // How many adjacent pages should be shown on each side? $adjacents = 3; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $query = "SELECT COUNT(*) as num FROM $tbl_name"; $total_pages = mysql_fetch_array(mysql_query($query)); $total_pages = $total_pages[num]; /* Setup vars for query. */ $targetpage = "index.php"; //your file name (the name of this file) $limit = 1; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ $sql = "SELECT 10 FROM $tbl_name LIMIT $start, $limit"; $result = mysql_query($sql); /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\"><img class=\"fltlft2\" src=\"http://www.djsmiley.net/images/Icons/Arrows/Previous.png\" height=\"25\" width=\"25\"></a>"; else $pagination.= "<span class=\"disabled\"><img class=\"fltlft2\" src=\"http://www.djsmiley.net/images/Icons/Arrows/Previous.png\" height=\"25\" width=\"25\"></a></span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\"><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Next.png\" height=\"25\" width=\"25\"></a>"; else $pagination.= "<span class=\"disabled\"><img src=\"http://www.djsmiley.net/images/Icons/Arrows/Next.png\" height=\"25\" width=\"25\"></span>"; $pagination.= "</div>\n"; } ?> <?php while($row = mysql_fetch_array($result)) { echo("<p class=NewsContainer><span class=NewsID>$type</span> <font size=5>$title</font><br><br> <em>posted by <strong>$user</strong> | added on $time</em><br><br> $message<br><br> <label class=fltlft2><img src=../images/Icons/Arrows/Right.png width=20 height=20/></label><a href=$url>Read more - $url</a> <div class=newsLikeShareRate> <table width=100% border=0> <tr> <td width=3% height=21><script src=http://connect.facebook.net/en_US/all.js#xfbml=1></script> <fb:like href='$url' show_faces=true width=450 font=arial></fb:like> </td> <td width=65%><a name=fb_share id=fb_share4 type=icon_link share_url=$url>Share</a> <script src=http://static.ak.fbcdn.net/connect.php/js/FB.Share type=text/javascript></script></td> <td width=32%>Rate this article: </td> </tr> </table> </div></p><br><br>");// Your while loop here } ?> <?=$pagination?> Hi guy seems to be having bit of trouble with this it gets first id then go's to pot when i hit the number 2 and so on nothing is there any help would be great Code: [Select] <?php $per_page = 1; $query = mysql_query("SELECT COUNT('id') FROM product"); $pages = ceil(mysql_result($query, 0) / $per_page); $page = (isset($_GET['id']) AND (int)$_GET['id'] > 0) ? (int)$_GET['id'] : 1; $start = ($page - 1) * $per_page; ?> <?php if(isset($_GET['id'])){ $id = $_GET['id']; $query = mysql_query("SELECT * FROM product WHERE productMenu=" . mysql_real_escape_string((int)$id) . " LIMIT {$start}, {$per_page}")or die(mysql_error()); while($row = mysql_fetch_assoc($query)){ ?> <div id="productHolder"> <div id="topprodlist"> <div id="prodName"><p>Product Name: <?php echo $row['productName']; ?></p></div> <div id="prodCode"><p>Code: <?php echo $row['code']; ?></p></div> <div id="prodSize"><p>Size: <?php echo $row['size']; ?></p></div> <div id="prodDiameter"><p>Diameter: <?php echo $row['diameter']; ?></p></div> </div> <div id="imageBox"><img src="prodimg/<?php echo $row['image']; ?>" width="100" height="100" alt="<?php echo $row['image']; ?>"></div> <div id="prodDescription"> <div id="descript"><h5>Description:</h5></div> <div id="prodTextBox"><p><?php echo $row['short']; ?></p> <a href="info.php?in=<?php echo $row['id']; ?> ">More Details:</a> </div> </div> <div id="clear"></div> </div> <?php }} ?> <?php if($pages >= 1){ for ($x=1; $x<=$pages; $x++){ echo "<a href=?id=$x> $x </a>"; } } ?> I need a little help trying to figure this out. I have a page that pulls up data, you can then click on one and go to a page with more detail. On this page you can use the PRrev & Next to go view another detail page on other data. My problem is if my 1st page has 6 sets of data on it but has a total of, say 50, you can only use the Prev & Next to view the 6. I want to be able to use the Prev & Next to go thru all 50. ie Page1 pulls this info data1 data2 data3 data4 data5 data6 < << 1 2 [3] 4 5 6 > >> Page2 Data 1 Lots of info about data 1 < Prev Next > You will only be able to view the 6 data sets in the table above, however there are 50 I want to be able to use the < Prev Next > to go to all of them Can someone help me with this? here is my code Page1 <?php session_start(); // session timing // set timeout period in seconds $inactive = 120; // check to see if $_SESSION['timeout'] is set if(isset($_SESSION['timeout']) ) { $session_life = time() - $_SESSION['timeout']; if($session_life > $inactive) { session_destroy(); } } $_SESSION['timeout'] = time(); // END session timing include('library/login.php'); login(); mysql_select_db('test'); // sets the sessions for all values $_SESSION=array_merge($_SESSION,$_POST); // echoing to verify $gender=$_SESSION[gender]; $genderPref=$_SESSION[genderPref]; echo "Chossen Gender".$_SESSION['gender']; echo "<br><Br>"; echo "GenderPref".$_SESSION['genderPref']; echo "<br><Br>"; // if the user has been timed out or not logged in if (!isset($_SESSION['clientID'])){ echo "You are not a register user - set this to a simple search form"; echo "<br><a href='form.php'>Form</a>"; } // user is logged in else { $clientID = $_SESSION['clientID']; $sql="SELECT * FROM user WHERE userID='$clientID'"; $result=mysql_query($sql); while ($r=mysql_fetch_array($result)) { $exp_date=$r["exp_date"]; $todays_date=date("Y-m-d"); } // verifies billing if ($exp_date >= $todays_date) { // billing is up to date $result = mysql_query("SELECT * FROM user WHERE gender='$gender'") or die(mysql_error()); // ------ Sets the display of data ------ $num_rows = mysql_num_rows($result); // number of rows to show per page $rowsperpage = 8; // find out total pages $totalpages = ceil($num_rows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; $result = mysql_query("SELECT * FROM user WHERE gender='$gender' LIMIT $offset, $rowsperpage")or die(mysql_error()); $num_rows = mysql_num_rows($result); if ($num_rows == 0){ echo "<div id='noResults'><span class='sorry'>Sorry</span>, no results found. <br> Please try again with broader search options.</div>"; } else { // format for search results $cells_wide = 2; echo " <table cellspacing='0' cellpadding='3' border='0' width='700'><tr> "; $c = 0; while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $gender=$r["gender"]; $aUserIDs[] = $userID; if (0 < $c && 0 == $c % $cells_wide){ echo " </tr><tr> "; } echo " <td width=175> "; echo "<a href='profileSession.php?userID=$r[userID]'>$userID</a>, $gender</td>"; $c++; } // end of while echo " </tr>"; echo " </table> "; } // -------- BUILD THE PAGINATION LINKS -------------------------------- $_SESSION['userID']=$aUserIDs; $_SESSION['userID2']=$aUserIDs2; echo "<div id='navigation'>"; // range of num links to show $range = 3; // if not on page 1, show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'>‹‹ </a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'> ‹ </a> "; } // END if ($currentpage > 1) // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($totalpages == 1) { echo ""; } else{ if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } // END if ($x == $currentpage) else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'>$x</a> "; } // END else } // END else } // END if (($x > 0) && ($x <= $totalpages)) } // END for loop // if not on last page, show forward and last page links if ($totalpages == 0) { echo ""; } else{ if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'> › </a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2'>›› </a> "; } // END if ($currentpage != $totalpages) }// END else echo "<br>currentpage=$currentpage&gender=$genderPref&genderPref=$gender&ageMin=$ageMin&ageMax=$ageMax&year1=$year1&year2=$year2"; $link='currentpage='; $link1='&gender='; $link2='&genderPref='; $link3='&ageMin='; $link4='&ageMax='; $link5='&year1='; $link6='&year2='; $total=$link.$currentpage.$link1.$genderPref.$link2.$gender.$link3.$ageMin.$link4.$ageMax.$link5.$year1.$link6.$year2; $_SESSION['pages']=$total; echo "<br>$total"; // -------- END PAGINATION -------------------------------------------- } // END if ($exp_date >= $todays_date) else { // billing has expired echo "Billing has expired<br>"; echo $_SESSION['clientID']; echo "<br><a href='session2.php'>Sesssion2</a>"; echo "<br><a href='form.php'>Form</a>"; } } // END valid session ?> Page2 <?php session_start(); // start up your PHP session! include('library/login.php'); login(); mysql_select_db('test'); $userID=$_GET["userID"]; $link=$_SESSION['pages']; // Sends back to display page echo "<a href='searchSession.php?$link' title='Back to Search'>Back to Search</a> "; // sets the Prev & Next $aUsers = isset($_SESSION['userID']) ? $_SESSION['userID'] : array(); $current = $userID; // Ok our current. $iCurKey = array_search($current, $aUsers); $prev = null; $next = null; if ($iCurKey !== false){ $prev = $iCurKey >= 1 ? $aUsers[$iCurKey - 1] : null; $next = $iCurKey < count($aUsers) - 1 ? $aUsers[$iCurKey + 1] : null; } // Lets do this simple. if ($prev !== null){ echo ' <A href="?userID=' . $prev . '">« Previous</A> '; } else{ echo " <span class='empty'>« Previous</span> "; } if ($next !== null){ echo '<A class=right href="?userID=' . $next . '">Next »</A> '; } else{ echo "<span class='empty'> Next »</span>"; } // END of the Prev & Next $result = mysql_query("SELECT userID, first_name, gender FROM user WHERE userID='$userID'") or die(mysql_error()); while ($r=mysql_fetch_array($result)){ $userID=$r["userID"]; $first_name=$r["first_name"]; $gender=$r["gender"]; } echo "<br>$userID, $first_name, $gender"; ?> I'm working on a flat file database that I can search. I got most of it done, but wondering how I can paginate the results.. <?php ini_set('display_errors', "On"); $count = 0; $time_start = microtime(true); $handle = fopen('/var/txtdb/links.txt', "r"); if ($handle) { while (!feof($handle) && $count < 15) { $line = fgets($handle, "4096"); $pos = strpos($line, "keyword"); if ($pos == true) { preg_match('~\[desc = ([^\]]*)\]~is', $line, $desc); echo "$desc[1]<br>"; $count++; } } fclose($handle); } $time_end = microtime(true); $time = $time_end - $time_start; echo '<br>Script took '.$time.' seconds to execute'; ?> So I want to display 15 results per page.. I know I could just loop through all the results each page just start from the last result +15 more. but.. that would take too long considering the amount of data I have. So is there a way to start the loop at a specific line? That way I won't have to loop through them all and waste time and slow things down.. Hi guys, please go to this url , http://mcfly1111.blogspot.com/2011/01/pagination.html . i typed out everything there. ifyou can correct my codes, that will be great but any help will be appreciated, thanks! Hi every one im getting an error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 SELECT * FROM Code: [Select] if(isset($_GET['subid'])){ $id = $_GET['subid']; } $query = mysql_query("SELECT * FROM sub_nav WHERE subNav_ID=" . mysql_real_escape_string((int)$id)); $row = mysql_fetch_assoc($query); $table = strtolower($row['subNavName']); // ******************************* This if statment controls the content ************************ if($row['show_hide'] == 1){ $per_page = 2; $pages_query = mysql_query("SELECT COUNT('id') FROM textiles"); $pages = ceil(mysql_result($pages_query, 0) / $per_page); $page = (isset($_GET['p']) AND (int)$_GET['p'] > 0) ? (int)$_GET['p'] : 1; $start = ($page-1) * $per_page; $query = mysql_query("SELECT imageName FROM textiles LIMIT $start, $per_page"); while ($query_row = mysql_fetch_assoc($query)){ echo '<p>',$query_row['imageName'] , '</p>'; } if ($pages >= 1){ for($x=1; $x<=$pages; $x++){ echo '<a href="?p='.$x.'">'.$x.'</a> '; } } Can any one help please I am building my uncle an online music catalogue and am trying to use pagination http://www.phpeasycode.com/pagination/ but for some reason it is only showing the cat_id data from the databse and even then its only the last entry. I need it to show all cat_id, song, artist and year from the database and not just the same ones over and over again. Here is a link to the page so you can see whats happening: http://www.nealeweb.com/steven2/ And here is the code, Can anybody tell me where i have gone wrong please. Code: [Select] $rpp = 24; // results per page $adjacents = 4; $page = intval($_GET["page"]); if($page<=0) $page = 1; $reload = $_SERVER['PHP_SELF']; // connect to your DB: $dbHost = ""; $dbUser = ""; $dbPass = ""; $dbname = ""; $db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db); // select appropriate results from DB: $requete = "SELECT cat_id, song, artist, year FROM tracks ORDER BY cat_id asc"; $result = mysql_query ($requete,$db); // count total number of appropriate listings: $tcount = mysql_num_rows($result); // count number of pages: $tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number $count = 0; $i = ($page-1)*$rpp; while(($count<$rpp) && ($i<$tcount)) { mysql_data_seek($result,$i); $query = mysql_fetch_array($result); // output each row: echo'<tr> <td valign="top" width="112" height="27"><span class="font">'.$catno.'</span></td> <td valign="top" width="536" height="27"><span class="font">'.$songname.'</span></td> <td valign="top"><span class="font" height="27">'.$artistname.'</span></td> <td valign="top" width="80" height="27"><span class="font">'.$ryear.'</span></td> </tr>'; $i++; $count++; } // call pagination function: include("paginate.php"); echo paginate_three($reload, $page, $tpages, $adjacents); Code: [Select] <?php $title="Search"; $metakeywords="search, find"; $metadescription="Search for your love!"; include ('header.php'); $getpage=clean_up($_GET['page']); $getpage = abs((int) ($getpage)); echo ' <table width="100%"><tr><td valign="top" class="content"> <form action="index.php?action=search" method="post"> <b>Seeking Gender</b> <select name="gender"> <option value="">Either</option> <option value="Male">Male</option> <option value="Female">Female</option> </select> <hr> <b>Smoke?</b> <select name="smoke"> <option value="">Doesn\'t matter</option> <option value="Yes">Yes</option> <option value="No">No</option> </select> <hr> <b>Drink?</b> <select name="drink"> <option value="">Doesn\'t matter</option> <option value="Yes">Yes</option> <option value="No">No</option> </select> <hr> <b>Body Type </b> <select name="bodytype"> <option value="">Doesn\'t matter</option> <option value="Slim / Slender">Slim / Slender</option> <option value="Athletic">Athletic</option> <option value="Average">Average</option> <option value="Some extra baggage">Some extra baggage</option> <option value="Body builder">Body builder</option> </select> </td><td valign="top" class="content"> <b>First Name</b> <input type="text" name="first" size="17"><br> <b>Last Name</b><input type="text" name="last" size="17"> <hr> <b>Sexual orientation</b> <select class="orientation" name="orientation"> <option value="">Any</option> <option value="Bi">Bi</option> <option value="Gay/Lesbian">Gay/Lesbian</option> <option value="Straight">Straight</option> </select> <hr> <b>Age Range</b> <select class="date" name="age_from">'; $years = range( 16, 100 ); foreach( $years as $v ) { echo "<option value=\"$v\">$v</option>\n"; } echo ' </select> to <select class="date" name="age_to">'; $yyears = range( 17, 100 ); foreach( $yyears as $v ) { echo "<option value=\"$v\">$v</option>\n"; } echo '</select> </td><td valign="top" class="content"> <b>Religion</b> <select name="religious"> <option value="">Any</option> <option value="Agnostic">Agnostic</option> <option value="Atheist">Atheist</option> <option value="Buddhist">Buddhist</option> <option value="Catholic">Catholic</option> <option value="Christian">Christian</option> <option value="Hindu">Hindu</option> <option value="Jewish">Jewish</option> <option value="Mormon">Mormon</option> <option value="Muslim">Muslim</option> <option value="Other">Other</option> <option value="Protestant">Protestant</option> <option value="Satanist">Satanist</option> <option value="Scientologist">Scientologist</option> <option value="Taoist">Taoist</option> <option value="Wiccan">Wiccan</option> </select> <hr> <b>Ethnicity</b> <select name="ethnicity"> <option value="">Any</option> <option value="Asian">Asian</option> <option value="Black / African descent">Black / African descent</option> <option value="East Indian">East Indian</option> <option value="Latino / Hispanic">Latino / Hispanic</option> <option value="Middle Eastern">Middle Eastern</option> <option value="Native American">Native American</option> <option value="Pacific Islander">Pacific Islander</option> <option value="White / Caucasian">White / Caucasian</option> <option value="Other">Other</option> </select> <hr> <b>Children</b> <select name="children"> <option value="">Doesn\'t matter</option> <option value="I don\'t want kids">I don\'t want kids</option> <option value="Love kids, but not for me">Love kids, but not for me</option> <option value="Undecided">Undecided</option> <option value="Someday">Someday</option> <option value="Expecting">Expecting</option> <option value="Proud parent">Proud parent</option> </select> <hr> <b>Education</b> <select name="education"> <option value="">Doesn\'t matter</option> <option value="High school">High school</option> <option value="Some college">Some college</option> <option value="In college">In college</option> <option value="College graduate">College graduate</option> <option value="Grad / professional school">Grad / professional school</option> <option value="Post grad">Post grad</option> </select> <br><input type="submit" name="submit" value="Search" /></form> </td></tr></table>'; if($_POST['submit'] || $_GET['page'] > "0"){ $first = clean_up($_POST['first']); $last = clean_up($_POST['last']); $smoke = clean_up($_POST['smoke']); $drink = clean_up($_POST['drink']); $gender = clean_up($_POST['gender']); $age_from = clean_up($_POST['age_from']); $age_to = clean_up($_POST['age_to']); $orientation = clean_up($_POST['orientation']); $religious = clean_up($_POST['religious']); $ethnicity = clean_up($_POST['ethnicity']); $bodytype = clean_up($_POST['bodytype']); $children = clean_up($_POST['children']); $education = clean_up($_POST['education']); if(!$_GET['page']){ if(!$first == ""){ setcookie("first", $first, time()+3600); } if(!$last == ""){ setcookie("last", $last, time()+3600); } if(!$smoke == ""){ setcookie("smoke", $smoke, time()+3600); } if(!$drink == ""){ setcookie("drink", $drink, time()+3600); } if(!$gender == ""){ setcookie("gender", $gender, time()+3600); } if(!$age_from == ""){ setcookie("age_from", "$age_from", time()+3600); } if(!$age_to == ""){ setcookie("age_to", "$age_to", time()+3600); } if(!$orientation == ""){ setcookie("orientation", $orientation, time()+3600); } if(!$religious == ""){ setcookie("religious", $religious, time()+3600); } if(!$ethnicity == ""){ setcookie("ethnicity", $ethnicity, time()+3600); } if(!$bodytype == ""){ setcookie("bodytype", $bodytype, time()+3600); } if(!$children == ""){ setcookie("children", $children, time()+3600); } if(!$education == ""){ setcookie("education", $education, time()+3600); } } $qquery = "SELECT `id`, `first`, `last`, `avatar`, `gender`, `about`, ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) AS age FROM `users` WHERE ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) BETWEEN $age_from AND $age_to"; // if any of the options that are stored in the `users` table are selected, add AND to the query string, //and store each needed part in an array, $users_criteria if( $gender != "" || $first != "" || $last != "" ) { $qquery .= ' AND '; $users_criteria = array(); if( !empty($gender) ) { $users_criteria[] = "`gender` = '$gender'"; } if( !empty($first) ) { $users_criteria[] = "`first` LIKE '%$first%'"; } if( !empty($last) ) { $users_criteria[] = "`last` LIKE '%$last%'"; } $qquery .= implode( ' AND ', $users_criteria ); // implode the array, separating each part with AND, and append to query string } // Same process as above, but for results that come from `questions` table if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) { $qquery .= ' AND id IN( SELECT `userid` FROM `questions` WHERE '; $questions_criteria = array(); if( !empty($smoke) ) { $questions_criteria[] = "`smoke` = '$smoke'"; } if( !empty($drink) ) { $questions_criteria[] = "`drink` = '$drink'"; } if( !empty($orientation) ) { $questions_criteria[] = "`orientation` = '$orientation'"; } if( !empty($religious) ) { $questions_criteria[] = "`religious` = '$religious'"; } if( !empty($ethnicity) ) { $questions_criteria[] = "`ethnicity` = '$ethnicity'"; } if( !empty($bodytype) ) { $questions_criteria[] = "`body_type` = '$bodytype'"; } if( !empty($children) ) { $questions_criteria[] = "`children` = '$children'"; } if( !empty($education) ) { $questions_criteria[] = "`education` = '$education'"; } $qquery .= implode( ' AND ', $questions_criteria ); $qquery .= ' )'; } $total = mysql_num_rows(mysql_query($qquery)); $page_count = ceil($total / 2); $page = 1; if (isset($getpage) && $getpage >= 1 && $getpage <= $page_count) { $page = (int)$getpage; } $skip = ($page - 1) * 2; $query = "SELECT `id`, `first`, `last`, `avatar`, `gender`, `about`, ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) AS age FROM `users` WHERE ( (DATE_FORMAT(CURDATE(),'%Y') - DATE_FORMAT(`bdate`, '%Y') ) - ( DATE_FORMAT(CURDATE(), '00-%m-%d') < DATE_FORMAT( `bdate`, '00-%m-%d')) ) BETWEEN $age_from AND $age_to"; // if any of the options that are stored in the `users` table are selected, add AND to the query string, //and store each needed part in an array, $users_criteria if( $gender != "" || $first != "" || $last != "" ) { $query .= ' AND '; $users_criteria = array(); if( !empty($gender) ) { $users_criteria[] = "`gender` = '$gender'"; } if( !empty($first) ) { $users_criteria[] = "`first` LIKE '%$first%'"; } if( !empty($last) ) { $users_criteria[] = "`last` LIKE '%$last%'"; } $query .= implode( ' AND ', $users_criteria ); // implode the array, separating each part with AND, and append to query string } // Same process as above, but for results that come from `questions` table if( $smoke != '' || $drink != '' || $orientation != '' || $religious != '' || $ethnicity != '' || $bodytype != '' ) { $query .= ' AND id IN( SELECT `userid` FROM `questions` WHERE '; $questions_criteria = array(); if( !empty($smoke) ) { $questions_criteria[] = "`smoke` = '$smoke'"; } if( !empty($drink) ) { $questions_criteria[] = "`drink` = '$drink'"; } if( !empty($orientation) ) { $questions_criteria[] = "`orientation` = '$orientation'"; } if( !empty($religious) ) { $questions_criteria[] = "`religious` = '$religious'"; } if( !empty($ethnicity) ) { $questions_criteria[] = "`ethnicity` = '$ethnicity'"; } if( !empty($bodytype) ) { $questions_criteria[] = "`body_type` = '$bodytype'"; } if( !empty($children) ) { $questions_criteria[] = "`children` = '$children'"; } if( !empty($education) ) { $questions_criteria[] = "`education` = '$education'"; } $query .= implode( ' AND ', $questions_criteria ); $query .= ' LIMIT $skip, 2 )'; } echo "<table width='100%' align='center'>"; if( $result = mysql_query( $query ) ) { if( mysql_num_rows($result) > 0 ) { while( $rr3 = mysql_fetch_assoc($result) ) { $user=clean_up($rr3[id]); $first=clean_up($rr3[first]); $last=clean_up($rr3[last]); $avatar=clean_up($rr3['avatar']); $about=clean_up($rr3[about]); echo "<tr><td valign='top' width='140' class='content'><center><img src='avatars/thumb/$avatar' /><br><a href='index.php?action=profile&id=$user'> $first $last</a></center></td><td class='content' valign='top'>".limitdesc($about)."</td></tr>"; } } else { echo '<tr><td colspan="2">Sorry, your search returned no results.</td></tr>'; } } else { echo '<tr><td colspan="2">We\'re sorry, there has been an error processing your request. Please try later.</td></tr>'; } echo "</table>"; echo "<div class='content'><center>"; if($getpage == 0 || $getpage == 1){}else{ $plink = $getpage - 1; echo " <a href='index.php?action=search&page=$plink'>Previous</a> "; } echo "<select id='ddp' onchange='document.location=(ddp.value)'> <option value=''>Page #</option>"; for ($i = 1; $i <= $page_count; ++$i){ echo ' <option value="index.php?action=search&page=' . $i . '">' . $i . '</option>'; } echo "</select>"; if($getpage == $page_count){}else{ if($page_count>1){ if($getpage == 0){ echo " <a href='index.php?action=search&page=2'>Next</a> "; }else{ $nlink = $getpage + 1; echo " <a href='index.php?action=search&page=$nlink'>Next</a> "; } } } echo "</center></div>"; } include ('footer.php'); ?> I keep getting these errors: Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home/gamersgo/public_html/datingsnap.com/header.php:4) in /home/gamersgo/public_html/datingsnap.com/pages/search.php on line 182 Warning: Cannot modify header information - headers already sent by (output started at /home/gamersgo/public_html/datingsnap.com/header.php:4) in /home/gamersgo/public_html/datingsnap.com/pages/search.php on line 183 the errors are coming from the setcookie lines. any idea why its spitting out that? and when I search, the results don't come out to two results per page. so the pagination isn't working right and i am getting those errors. any ideas? Is there a way of doing pagination other than going through the whole big file, like: Code: [Select] $limit = "LIMIT 0, 30"; if ($_GET['page'] == 2) { $limit = "LIMIT 30, 30"; } $sql = "SELECT * FROM table WHERE blah = 'blah' $limit"; $result = mysql_query($sql); But is there a way to do this without having to write an if statement for each page without getting to extensive? Thanks! I am trying to code a php, mysql and jquery pagination much like the way twitter's pagination works. Page 1 i have Code: [Select] <div id="load_more"> <?php $query = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 5"); while($row = mysql_fetch_assoc($query)){ $id = $row['id']; // show comments code } ?> </div> <script type="text/javascript"> $(function() { $('.showmore').live("click",function() { var ID = $(this).attr("id"); if(ID) { $("#more"+ID).html('<img src="ajax-loader.gif" />'); $.ajax({ type: "POST", url: "comments_more.php", data: "lastmsg="+ ID, cache: false, success: function(html){ $("#load_more").append(html); $("#more"+ID).remove(); // removing old more button } }); } else { $(".morebox").html('No more comments.');// no results } return false; }); }); </script> <div id="more<?php echo $id; ?>" class="morebox"> <a href="javascript:;" style="text-decoration: none; font-size: 12px; color: #ffffff; font-weight: bold; " class="showmore" id="<?php echo $id; ?>">Load More Comments</a> </div> So i am only showing 5 rows untill the link is clicked and then i want it to load more comments from comments_more.php which is the same page as above just it checks for the lastmsg id and alters the query to WHERE id < '$lastmsg'. Everything works ok for clicking the link and showing more results but it only works once. even if there is more than 10 rows it will show as "no more comments" after 10. Any help will be appreciated thanks. The problem here is my pagination. It works for the most part. The only part that does NOT work is that when I go to a page OTHER THAN the first page it WILL NOT allow me to click on the edit link and go to the edit matchtype form. It allows me to on the first page of list but not for any after that. Code: [Select] <?php error_reporting(E_ALL); // Include the database page include ('../inc/dbconfig.php'); $query = "SELECT CONCAT_WS(' ', handlers.firstName, handlers.lastName) AS name, DATE_FORMAT(matchTypes.dateCreated, '%M %d, %Y') AS dateCreated, matchTypes.ID, matchTypes.matchType FROM matchTypes INNER JOIN handlers ON matchTypes.creatorID = handlers.ID WHERE matchTypes.enabled = '0' ORDER BY matchTypes.matchType"; $result = mysqli_query ( $dbc, $query ); // Run The Query $rows = mysqli_num_rows($result); $itemsPerPage = 10; $pages = ceil( $rows / $itemsPerPage ); ?> <script> $(document).ready(function() { $('a', $('div#addform')).click(function() { $('#innerContent').load('forms/' + $(this).attr('id') + '.php?case=addnew'); }); // Add the table sorter and table paginator plugins $('#matchTypesPageList').tablesorter() .tablesorterPager({ container: $( '#matchTypesPageList .paginate' ), cssPageLinks: 'a.pageLink' }); $('.edit').click(function(){ var matchTypeID = $(this).attr('rel'); $('#innerContent').load('forms/matchtype.php?id=' + matchTypeID + '&case=edit'); }); $('.delete').click(function(){ var matchTypeID = $(this).attr('rel'); var dataString = 'matchTypeID=' + matchTypeID + '&deleteMatchType=True'; $.ajax({ type: "POST", url: "processes/matchtype.php", data: dataString, }); var table = $(this).closest("table"); if (table.find("tr").length == 3) { table.remove(); } else { $(this).closest("tr").remove(); } }); }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Match Types</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> <!-- newPost --> <div id="addform" class="newPost actionBlock"> <a href="#" id="matchtype" class="button"><strong>Add New Match Type<img src="img/icons/add_48.png" alt="new post" class="icon "/></strong></a> </div> <!-- /newPost --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <!-- ListHeader --> <div id="listHeader"> <p class="listInfos"> You have <?php echo $rows; ?> match types. </p> </div> <!-- /ListHeader --> <!-- ListTable --> <?php if ($rows > 0) { ?> <table cellspacing="0" class="listTable" id="matchTypesPageList"> <!-- Thead --> <thead> <tr> <th class="first"><div><a href="#" title="Match Type Name">Match Type Name</a></div></th> <th><a href="#" title="Creator">Creator</a></th> <th><a href="#" title="Date Created">Date Created</a></th> <th class="last">Edit/Delete</th> </tr> </thead> <!-- /Thead --> <!-- Tfoot --> <tfoot> <tr> <td colspan="4"> <div class="inner"> <div class="paginate"> <?php if( $pages > 1 ) { for( $i = 1; $i <= $pages; $i++ ) { echo '<span style="padding-left: 5px; padding-right: 5px;"><a class="pageLink" href="#">' . $i . '</a></span>'; } } ?> </div> </div> </td> </tr> </tfoot> <!-- /Tfoot --> <!-- Tbody --> <tbody> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { echo ' <tr> <td>' . $row['matchType'] . '</td> <td>' . $row['name'] . '</td> <td>' . $row['dateCreated'] . '</td> <td style="text-align:center;"><img src="img/notepad.png" class="edit" rel="' . $row['ID'] . '"/><img src="img/Delete-icon.png" class="delete" rel="' . $row['ID'] . '"/></td> </tr>'; } ?> </tbody> <!-- /Tbody --> </table> <?php } ?> <!-- /ListTable --> </div> <!-- /Inner Content --> My php/mysql book doesn't cover pagination so I've been searching the web for a simple pagination script that I can learn from. I got the following one working at http://www.phpsimplicity.com/tips.php?id=1 but it's just showing the next and prev links... no results on the pages and you can click on the next link forever when there's only 11 records in the table I queried. How can I display results on each page and have the info append to the next page? This is the second example I've tried and none seem to explain this part? i have some code which checks all of the posts in the database with the topic_id of $topic_id. what i want to do is like on many forums. On the topic list next to the name just show the pages like: Code: [Select] 1-2-3-4 and when there are more than 4 or so Code: [Select] 1-2....8-9 here is the code which gets the number of pages: $data = $db->query("SELECT * FROM ".DB_PREFIX."posts WHERE topic_id = '$topic_info->topic_id'"); $rows = mysql_num_rows($data); $page_rows = $posts_per_page; if ($rows > $page_rows) { $rowsArray = array($rows); } as you can see i have added it into an array but i dont know what to do from there. I guessed it would be something like a for statement but im not sure. Can anyone help? Hi Guys, I tried to put pagination code into my search results but every time I get an ugly error. Can you guys help me please?I just want to put 5 results per page. Why does it have to be so complicated. I am just asking something very simple (Well, it shows that you don't know anything about php dude! ( I am just talking to myself)) <a href="search.php">Search</a><br> <br> <?php include("connect.php"); $first_name = "%" . $_POST["first_name"] . "%"; $last_name = "%" . $_POST["last_name"] . "%"; $age = "%" . $_POST["age"] . "%"; $query= "SELECT * FROM `contacts` WHERE `first_name` LIKE '$first_name' AND `last_name` LIKE '$last_name' AND `age` LIKE '$age' ORDER BY `contacts`.`first_name` ASC LIMIT 0, 30 "; $result = mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $first_name = mysql_result($result,$i,"first_name"); $last_name = mysql_result($result,$i,"last_name"); $age = mysql_result($result,$i,"age"); $id = mysql_result($result,$i,"id"); echo "<b>first name:</b> $first_name<br>"; echo "<b>last name:</b> $last_name<br>"; echo "<b>age:</b> $age<br>"; echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>"; echo "<br><br>"; ++$i; } } else { echo "No Results"; }?> |