PHP - Help In Pagination Without Mysql
hi every one thanks for this forum i want help please
i want add pagination to this script and listed the floder by last modification
<table width='100%' border='0'> <?php $gr = "music/Musique-Maghreb/"; $gr="music/$cat/"; $rep=opendir($gr); $c=1; while ($file = readdir($rep)){ if($file != '..' && $file !='.' && $file !=''){ if (file_exists("images/$file.jpg")) { $img="images/$file.jpg"; } else { $img="images/nophoto.jpg"; } if ($c==1) { echo "<tr>"; } ?> <?php echo $file;?> </tr> <TR> <tr> <td> </td> </tr> </tbody> </table><?php if($c==5) { echo "</tr>"; $c=0; } $c++; } } closedir($rep); clearstatcache(); ?> </td> </center></div> </table> Similar TutorialsARGHHHHH pagination, again? I know! OK here is a code that I worked on to get a grocery store items list displayed in a table in a paginated design. Everything is working fine except I don't know how to dynamically display auto incremented indexID range on that particular page, like 1-10 11-20 21-30 31-40 and so on (something like amazon items in cart) instead of page numbers << < 1 2 3 4 > >> as pagination hyperlink to move between different pages. Any help will be greatly appreciated. Code: [Select] <?php // database connection info $conn = mysql_connect('host','user','password') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('dbName',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM store"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 10; // find out total pages $totalpages = ceil($numrows / $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; // get the info from the db $sql = "SELECT indexID, item, price FROM store LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... echo "<p><table><tr><td><strong>Item</strong></td><td><strong>Price</strong></td></tr>"; while ($list = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>" . $list['item'] . "</td>"; echo "<td>$" . $list['price'] . "</td>"; echo "</tr>"; } // end while echo "</table></p><br /><br />"; /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // 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 ($x == $currentpage) { // 'highlight' it but don't make a link echo " <b>$x</b> "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?> I would like to know what is the best method (the most intelligent and comfortable for users) to paginate a result table with PHP/MySQL? Provided I have a result set of 100 pages. Method 1: <select> <option>1</option> .... </select> Method 2: Link on Page 1, 2, 3 ... 100 If there is any algorithm with PHP for automated these displays, please demonstrate it. i've found a pagination script of the internet but the image comes up blank. I've stored it in a largeblob. When i check the html it says 'array[name]' as the image pz help me heres the code: <?php //connection stuff here $page = 1; if ( isset( $_GET['page'] ) ) { $page = (int) $_GET['page']; } $query = mysql_query("SELECT COUNT(*) FROM `upload`",$link); list( $total ) = mysql_fetch_row( $query ); $total = ceil( $total / $perPage ); $start = ( $perPage * ( $page - 1 ) ); $limit = ''; $show = true; if ( $total > 1 ) { $limit = " LIMIT {$start}, {$perPage}"; } else { $show = false; } $query = mysql_query("SELECT * FROM `upload` ORDER BY `id`{$limit}"); while( $row = mysql_fetch_assoc( $query ) ) { echo "<img src=\"{$row['file_name']}\" alt=\"{$row['name']}\" title=\"{$row['name']}\" />"; } if ( $show ) { $prev = $page - 1; $next = $page + 1; if ( $prev > 0 ) { echo "<a href=\"{$thispage}?page={$prev}\">[PREV]</a>"; } if ( $next < $total ) { echo "<a href=\"{$thispage}?page={$next}\">[NEXT]</a>"; } } ?> Hi There! Hopefully someone can help. I'm looking for some php script that allows me to display mysql table data in alternating row colors (eg 5 columns and 500 rows). I would also like to add pagination and limit number of rows displayed at a time to e.g. 50. If possible I'd like to be able to sort asc/desc using titles(links) at the top of the displayed data. Hopefully someone may have a script like this that also shows the mysql connection code (sample host, pass, user etc...) - a working php file so to speak that I can edit. Would really appreciate the help. If you could recommend some software or a wizard that could generate the php code for me I would really appreciate it too! THANKS! Hi, my page is currently up at brewhas.org/transactions.php. When I retrieve a set of results > the defined # per page (such as entering 'WI' for last name), I see the first page correctly, and see the links to next pages, but when I go to the next page there are no results displayed. Same for p.3, etc. So I've looked around enough to know that I need to pass a variable to the subsequent pages, either via a session variable or the URL. I have 2 fields input on the form, as well as a limit and offset. My questions are 1) do I need to pass all 4 and if so then should I use a session variable so the URL does not get too long, and 2) can anyone provide any help with setting session variables and including them to be passed? I'm a newbie and have grabbed some code where I can but this is where i'm stuck. thanks in advance. Code: [Select] <?php include 'config.php'; include 'opendb.php'; $rows_per_page = 20; //Get the values from the text boxes $fnamesearch = $_POST["fnamesearch"]; $lnamesearch = $_POST["lnamesearch"]; //These trim and convert the name fields to upper case. $fnamesearch=strtoupper($fnamesearch); $lnamesearch=strtoupper($lnamesearch); $fnamesearch=trim($fnamesearch); $lnamesearch=trim($lnamesearch); // Count how many rows are coming back for the query //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT COUNT(*) FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the get count query $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; echo "count: ".$numrows; $lastpage = ceil($numrows/$rows_per_page); //determines how many pages based on rows divided by rows per page echo "pages: ".$lastpage; // Get required page number. If not present, default to 1. if (isset($_GET['pageno']) && is_numeric($_GET['pageno'])) {$pageno = $_GET['pageno']; } else {$pageno = 1; } //Checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; if ($pageno > $lastpage) {$pageno = $lastpage; } if ($pageno < 1) {$pageno = 1; } //constructs OFFSET for the sql SELECT statement $offset = ($pageno - 1) * $rows_per_page; //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT * FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%')) LIMIT $offset, $rows_per_page"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the query //Count the number of results $numrows=mysql_num_rows($result); echo "<p class='style7'>Your search: "".$fnamesearch." ".$lnamesearch."" returned <b>".$numrows."</b> results.</p>"; if ($numrows == 0) //if no matches, don't display the table exit; else //build the table and insert rows { echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=left bordercolor=#666666>"; echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>"; echo "<th width='10%' class='style5'>Action</th>"; echo "<th width='12%' class='style5'>From</th>"; echo "<th width='12%' class='style5'>To</th>"; echo "<th width='5%' class='style5'>Pos</th>"; echo "<th width='18%' class='style5'>Name</th>"; echo "<th width='5%' class='style5'>Round</th></tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>"; echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>"; echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>"; echo "<td width='12%' class='style6'>".$row['TO_OWNER']."</td>"; echo "<td width='5%' class='style6'>".$row['POSITION']."</td>"; echo "<td width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>"; echo "<td width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>"; } /****** build the pagination links ******/ // if not on page 1, don't show back links if ($pageno > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'><<</a> "; // get previous page num $prevpage = $pageno - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><</a> "; } // range of num links to show $range = 3; // loop to show links to range of pages around current page for ($x = ($pageno - $range); $x < (($pageno + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $lastpage)) { // if we're on current page... if ($x == $pageno) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$x'>$x</a> "; } // end else } // end if } // if not on last page, show forward and last page links if ($pageno != $lastpage) { // get next page $nextpage = $pageno + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>>></a> "; } // end if /****** end build pagination links ******/ echo "</table>"; } mysql_free_result($result); //release the result set from the table mysql_close($conn); //close the connection to the db ?> MOD EDIT: [code] . . . [/code] tags added. Hi guys, I have a question about pagination. It's not really about the coding side so I'm really sorry if this is the wrong section! Ok my question is, does pagination actually create multiple pages? I'm really new to PHP and I'm just reading through different things and tutorials to try and figure it out if you will. So does it create new pages? From my understanding it simply changes a variable to a page number and uses that page number (and simple matH) to figure out what rows to show. If this is the case, how do people use pagination to create links such as http://example.com/imnooby/page-1 http://example.com/imnooby/page-2 http://example.com/imnooby/page-3 Surely if this was all just one page, it would just be http://example.com/imnooby/page and the variable would change depending on the button, but the same page would be reloaded? This is the part that's really bugging me and any explanation would really help. Hello, I am trying to incorporate pagination to only show 20 rows per page but instead the links work but shows all rows on all pages. Link to see: http://webjax.99k.org/ Full Code: Code: [Select] <?php include ("./header.php"); //PAGINATION $sql = "SELECT COUNT(*) FROM servers"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 20; // find out total pages $totalpages = ceil($numrows / $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; //END PAGINATION //======================================================================== Commands If (isSet($_GET['sort'])) { $sortby = $_GET['sort']; If ($sortby=='name' || $sortby=='ip' || $sortby=='votes' || $sortby=='username') { If ($sortby=='name') { $options = "<option value='./index.php?sort=name' selected='selected'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($sortby=='ip') { $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip' selected='selected'>IP Address</option> <option value='./index.php?sort=votes'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($sortby=='votes') { $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes' selected='selected'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($sortby=='username') { $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes'>Rank</option> <option value='./index.php?sort=username' selected='selected'>Owner</option>"; } } else { $sortby = "votes"; $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes' selected='selected'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } } else { $sortby = "votes"; $options = "<option value='./index.php?sort=name'>Name</option> <option value='./index.php?sort=ip'>IP Address</option> <option value='./index.php?sort=votes' selected='selected'>Rank</option> <option value='./index.php?sort=username'>Owner</option>"; } If ($_GET['act']=='see' && isSet($_GET['id'])) { //=================================================================== XSS protection $sid = str_replace("/", "", $_GET['id']); $sid = str_replace(Chr(92), "", $sid); $sid = str_replace("'", "", $sid); $sid = str_replace('"', "", $sid); $sid = str_replace("<", "", $sid); $sid = str_replace(">", "", $sid); $sid = str_replace("-", "", $sid); $sid = str_replace("union", "", $sid); $sid = str_replace("information_schema", "", $sid); $sid = strtolower(trim($sid)); //=================================================================== XSS protection $result = mysql_query("SELECT * FROM servers WHERE id='$sid'") or die (mysql_error()); $nr = mysql_num_rows($result); If ($nr<='0') { $exist = "No"; } else { $exist = "Yes"; while($row = mysql_fetch_array($result)) { If ($row['name']=='') { $servername = "<img src='./banners/" .$row['banner']. "' style='width:468px;height:60px' title='Server details'>"; } else { $servername = $row['name']; } $did = $row['id']; $dname = $row['name']; $dbanner = $row['banner']; $dip = $row['ip']; $ddescription = $row['description']; $dwebsite = $row['website']; $dcountry = $row['country']; $dsponsored = $row['sponsored']; $dvotes = $row['votes']; $mineq = $row['mineq']; $dusername = $row['username']; $ddate = $row['date']; If ($dusername==$username) { $me = "Yes"; } else { $me = "No"; } If ($mineq=='Yes') { If (!$dip=='') { include ("./minequery.class.php"); $mine = array((Minequery::query($dip))); $donlinep = $mine["0"]["playerCount"]; If ($donlinep>0) { for ($i = 0; $i <= $donlinep; $i++) { $playername = $mine["0"]["playerList"][$i]; If (!$playername=='') { $donline .= $playername. ", "; } } $donline = left($donline, strlen($donline)-2); } } else { $donline = "<i>n/a</i>"; } } else { $donline = "<i>n/a</i>"; } } } } If ($_GET['act']=='' || $_GET['act']=='sponsored' || $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers ORDER BY votes DESC") or die (mysql_error()); while($rk_list[] = mysql_fetch_array($result)); If (isSet($username) && $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers WHERE username='$username' ORDER BY id DESC") or die (mysql_error()); } else { If ($_GET['act']=='sponsored') { $result = mysql_query("SELECT * FROM servers WHERE sponsored='Yes' ORDER BY id DESC") or die (mysql_error()); } else { If (isSet($_GET['country'])) { $result = mysql_query("SELECT * FROM servers WHERE country='$_GET[country]' ORDER BY votes DESC") or die (mysql_error()); } else { $result = mysql_query("SELECT * FROM servers ORDER BY $sortby DESC") or die (mysql_error()); } } } $nr = mysql_num_rows($result); If ($nr<='0') { $serverslist = "<tr><td align='center' colspan='6'>There are no servers added yet !</td></tr>"; } else { include ("./minequery.class.php"); $rank = "0"; while($row = mysql_fetch_array($result)){ $data[] = $row; } foreach ($data as $row) { $rank = ($rank + 1); If ($row['banner']=='') { $servername = $row['name']; } else { $servername = "<img src='" .$row['banner']. "' style='width:400px;height:60px' title='Server details'>"; } If ($row['sponsored']=='Yes') { $star = "style='background:url(./images/star.png);background-repeat:no-repeat;'"; } else { $star = ""; } If ($row['mineq']=='Yes') { If (!$row['ip']=='') { $mine = array((Minequery::query($row['ip']))); $onlinep = $mine["0"]["playerCount"]; } else { $onlinep = "<i>n/a</i>"; } } else { $onlinep = "<i>n/a</i>"; } $country = "./flags/" .$row['country']. ".png"; $serverslist .= "<tr><td align='center'>" .(array_search($row, $rk_list) + 1). "</td><td align='center'><a href='./index.php?country=" .$row['country']. "'><img src='" .$country. "' title='" .$row['country']. "' style='width:32px;height:32px;'></a></td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center' " .$star. ">" .$row['ip']. "</td><td align='center'>" .$onlinep. "</td><td align='center'>" .$row['votes']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center'><img src='./flags/" .$row['country']. ".ico' title='" .$row['country']. "'> " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td><td align='center'>" .$row['date']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center'>" .$servername. "</td><td align='center'>" .country_flag($row['ip']). " " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td></tr>"; } } } /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // 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 ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ //======================================================================== Strings $countries = "<option>Afghanistan</option> <option>Albania</option> <option>Algeria</option> <option>Andorra</option> <option>Angola</option> <option>Antigua and Barbuda</option> <option>Argentina</option> <option>Armenia</option> <option>Aruba</option> <option>Australia</option> <option>Austria</option> <option>Azerbaijan</option> <option>Bahamas, The</option> <option>Bahrain</option> <option>Bangladesh</option> <option>Barbados</option> <option>Belarus</option> <option>Belgium</option> <option>Belize</option> <option>Benin</option> <option>Bermuda</option> <option>Bhutan</option> <option>Bolivia</option> <option>Bosnia and Herzegovina</option> <option>Botswana</option> <option>Brazil</option> <option>Brunei</option> <option>Bulgaria</option> <option>Burkina Faso</option> <option>Burma</option> <option>Burundi</option> <option>Cambodia</option> <option>Cameroon</option> <option>Canada</option> <option>Cape Verde</option> <option>Cayman Islands</option> <option>Central African Republic</option> <option>Chad</option> <option>Chile</option> <option>China</option> <option>Colombia</option> <option>Comoros</option> <option>Congo, Democratic Republic of the</option> <option>Congo, Republic of the</option> <option>Costa Rica</option> <option>Cote d'Ivoire</option> <option>Croatia</option> <option>Cuba</option> <option>Curacao</option> <option>Cyprus</option> <option>Czech Republic</option> <option>Denmark</option> <option>Djibouti</option> <option>Dominica</option> <option>Dominican Republic</option> <option>Ecuador</option> <option>Egypt</option> <option>El Salvador</option> <option>Equatorial Guinea</option> <option>Eritrea</option> <option>Estonia</option> <option>Ethiopia</option> <option>Fiji</option> <option>Finland</option> <option>France</option> <option>Gabon</option> <option>Gambia</option> <option>Georgia</option> <option>Germany</option> <option>Ghana</option> <option>Greece</option> <option>Grenada</option> <option>Guatemala</option> <option>Guinea</option> <option>Guinea-Bissau</option> <option>Guyana</option> <option>Haiti</option> <option>Holy See</option> <option>Honduras</option> <option>Hong Kong</option> <option>Hungary</option> <option>Iceland</option> <option>India</option> <option>Indonesia</option> <option>Iran</option> <option>Iraq</option> <option>Ireland</option> <option>Israel</option> <option>Italy</option> <option>Jamaica</option> <option>Japan</option> <option>Jordan</option> <option>Kazakhstan</option> <option>Kenya</option> <option>Kiribati</option> <option>Kosovo</option> <option>Kuwait</option> <option>Kyrgyzstan</option> <option>Laos</option> <option>Latvia</option> <option>Lebanon</option> <option>Lesotho</option> <option>Liberia</option> <option>Libya</option> <option>Liechtenstein</option> <option>Lithuania</option> <option>Luxembourg</option> <option>Macau</option> <option>Macedonia</option> <option>Madagascar</option> <option>Malawi</option> <option>Malaysia</option> <option>Maldives</option> <option>Mali</option> <option>Malta</option> <option>Marshall Islands</option> <option>Mauritania</option> <option>Mauritius</option> <option>Mexico</option> <option>Micronesia</option> <option>Moldova</option> <option>Monaco</option> <option>Mongolia</option> <option>Montenegro</option> <option>Morocco</option> <option>Mozambique</option> <option>Namibia</option> <option>Nauru</option> <option>Nepal</option> <option>Netherlands</option> <option>Netherlands Antilles</option> <option>New Zealand</option> <option>Nicaragua</option> <option>Niger</option> <option>Nigeria</option> <option>North Korea</option> <option>Norway</option> <option>Oman</option> <option>Pakistan</option> <option>Palau</option> <option>Panama</option> <option>Papua New Guinea</option> <option>Paraguay</option> <option>Peru</option> <option>Philippines</option> <option>Poland</option> <option>Portugal</option> <option>Qatar</option> <option>Romania</option> <option>Russia</option> <option>Rwanda</option> <option>Saint Kitts and Nevis</option> <option>Saint Lucia</option> <option>Saint Vincent and the Grenadines</option> <option>Samoa</option> <option>San Marino</option> <option>Sao Tome and Principe</option> <option>Saudi Arabia</option> <option>Senegal</option> <option>Serbia</option> <option>Seychelles</option> <option>Sierra Leone</option> <option>Singapore</option> <option>Slovakia</option> <option>Slovenia</option> <option>Solomon Islands</option> <option>Somalia</option> <option>South Africa</option> <option>South Korea</option> <option>South Sudan</option> <option>Spain</option> <option>Sri Lanka</option> <option>Sudan</option> <option>Suriname</option> <option>Swaziland</option> <option>Sweden</option> <option>Switzerland</option> <option>Syria</option> <option>Taiwan</option> <option>Tajikistan</option> <option>Tanzania</option> <option>Thailand</option> <option>Timor-Leste</option> <option>Togo</option> <option>Tonga</option> <option>Trinidad and Tobago</option> <option>Tunisia</option> <option>Turkey</option> <option>Turkmenistan</option> <option>Tuvalu</option> <option>Uganda</option> <option>Ukraine</option> <option>United Arab Emirates</option> <option>United Kingdom</option> <option>Uruguay</option> <option>Uzbekistan</option> <option>Vanuatu</option> <option>Venezuela</option> <option>Vietnam</option> <option>Yemen</option> <option>Zambia</option> <option>Zimbabwe</option>"; $servers = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='6'>Servers list</th></tr> <tr><td align='left' colspan='3'>Servers : " .$nr. "</td><td align='right' colspan='3'>Arrange by : <select name='by' onChange=location.href=this.options[this.selectedIndex].value;>" .$options. "</select></td></tr> <tr><th align='center' width='1%'>#</th><th align='center' width='1%'>Country</th><th align='center' width='47%'>Name / Banner</th><th align='center' width='20%'>IP Address</th><th align='center' width='1%'>Players Online</th><th align='center' width='1%'>Votes</th></tr> " .$serverslist. " </table>"; $addsv = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Add server</th></tr> <tr><td align='left' width='100px'>Name :</td><td align='left'><input class='field' type='text' name='aname' style='width:100%;'></td></tr> <tr><td align='left'>Banner url :</td><td align='left'><input class='field' type='text' name='abanner' style='width:100%;'></td></tr> <tr><td align='left'>Description :</td><td align='left'><textarea class='textarea' name='adescription'></textarea></td></tr> <tr><td align='left'>IP Address :</td><td align='left'><input class='field' type='text' name='aip'></td></tr> <tr><td align='left'>Website :</td><td align='left'><input class='field' type='text' name='awebsite'></td></tr> <tr><td align='left'>Country :</td><td align='left'><select name='acountry'>" .$countries. "</select></td></tr> <tr><td align='left'>MineQuery :</td><td align='left'><select name='amine'><option selected='selected'>Yes</option><option>No</option></select></td></tr> <tr><td align='left'>Captcha :</td><td align='left'><img src='./captcha.php' title='Captcha'> <input class='field' type='text' name='captcha' style='width:100px;' maxlength='5'></td></tr> <tr><td> </td><td align='left'><input type='submit' name='aok' value='Add'></td></tr> </table>"; $login = "<table align='left' class='fancy' width='40%'> <tr><th align='left' colspan='2'>Login</th></tr> <tr><td align='left' width='30%'>Username :</td><td align='left'><input class='field' type='text' name='lname'></td></tr> <tr><td align='left'>Password :</td><td align='left'><input class='field' type='password' name='lpass'></td></tr> <tr><td> </td><td align='left'><input type='submit' name='lok' value='Login'></td></tr> </table>"; $register = "<table align='left' class='fancy' width='45%'> <tr><th align='left' colspan='2'>Register</th></tr> <tr><td align='left' width='30%'>Username :</td><td align='left'><input class='field' type='text' name='rname'> <font color='red'>*</font></td></tr> <tr><td align='left'>E-mail :</td><td align='left'><input class='field' type='text' name='rmail'> <font color='red'>*</font></td></tr> <tr><td align='left'>Password :</td><td align='left'><input class='field' type='password' name='rpass'> <font color='red'>*</font></td></tr> <tr><td align='left'>Re-Password :</td><td align='left'><input class='field' type='password' name='rrepass'> <font color='red'>*</font></td></tr> <tr><td> </td><td align='left'><input type='submit' name='rok' value='Register'></td></tr> </table>"; $settings = "<table align='left' class='g' width='80%'> <tr><th align='left' colspan='2'>Settings</th></tr> <tr><td width='50%' valign='top'> <table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>My account</th></tr> <tr><td align='left'>E-mail : </td><td align='left'>" .$uemail. "</td></tr> <tr><td align='left'>Servers : </td><td align='left'>" .$uservers. "</td></tr> <tr><td align='left'>Next vote : </td><td align='left'>" .$unextvoted. "</td></tr> <tr><td align='left'>Join date : </td><td align='left'>" .$udate. "</td></tr> </table> </td><td width='50%' valign='top'> <table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Change password</th></tr> <tr><td align='left'>Current password : </td><td align='left'><input type='password' name='cpass'></td></tr> <tr><td align='left'>New password : </td><td align='left'><input type='password' name='cnpass'></td></tr> <tr><td align='left'>New re-password : </td><td align='left'><input type='password' name='cnrepass'></td></tr> <tr><td> </td><td align='left'><input type='submit' name='cok' value='Change'></td></tr> </table> </td></tr> </table>"; $f = fopen("./mine.txt", "r"); while ($line = fgets($f, 9999)) { $minetext .= $line. ""; } fclose($f); $minequery = "<table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>MineQuery</th></tr> <tr><td align='left'> " .$minetext. " </td></tr> </table>"; $f = fopen("./help.txt", "r"); while ($line = fgets($f, 9999)) { $helptext .= $line. ""; } fclose($f); $help = "<table align='left' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Help</th></tr> <tr><td align='left'> " .$helptext. " </td></tr> </table>"; If ($me=='No') { If ($dname=='') { $dname = "<i>none</i>"; } If ($dbanner=='') { $dbanner = "<i>none</i>"; } else { $dbanner = "<img src='" .$dbanner. "' title='Banner' style='width:468px;height:60px'>"; } $details = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Server details</th></tr> <tr><td align='left' width='100px'>Name :</td><td align='left'>" .$dname. "</td></tr> <tr><td align='left'>Banner url :</td><td align='left'>" .$dbanner. "</td></tr> <tr><td align='left'>Description :</td><td align='left'>" .$ddescription. "</td></tr> <tr><td align='left'>Players online :</td><td align='left'>" .$donline. "</td></tr> <tr><td align='left'>IP Address :</td><td align='left'>" .$dip. "</td></tr> <tr><td align='left'>Website :</td><td align='left'>" .$dwebsite. "</td></tr> <tr><td align='left'>Sponsored :</td><td align='left'>" .$dsponsored. "</td></tr> <tr><td align='left'>Votes :</td><td align='left'>" .$dvotes. "</td></tr> <tr><td align='left'>Owner :</td><td align='left'>" .$dusername. "</td></tr> <tr><td align='left'>Added at :</td><td align='left'>" .$ddate. "</td></tr> <tr><td align='left'>Vote link :</td><td align='left'><a class='nav' href='" .$siteurl. "/vote.php?id=" .$did. "' title='Vote link'>" .$siteurl. "/vote.php?id=" .$did. "</td></tr> </table>"; } else { $details = "<table align='center' class='fancy' width='100%'> <tr><th align='left' colspan='2'>Server details</th></tr> <tr><td align='left' width='100px'>Name :</td><td align='left'><input class='field' type='text' name='nname' style='width:700px;' value='" .$dname. "'></td></tr> <tr><td align='left'>Banner url :</td><td align='left'><input class='field' type='text' name='nbanner' style='width:700px;' value='" .$dbanner. "'></td></tr> <tr><td align='left'>Description :</td><td align='left'><textarea class='textarea' name='ndescription'>" .$ddescription. "</textarea></td></tr> <tr><td align='left'>Players online :</td><td align='left'>" .$donline. "</td></tr> <tr><td align='left'>IP Address :</td><td align='left'><input class='field' type='text' name='nip' value='" .$dip. "'></td></tr> <tr><td align='left'>Website :</td><td align='left'><input class='field' type='text' name='nwebsite' value='" .$dwebsite. "'></td></tr> <tr><td align='left'>Vote link :</td><td align='left'><a class='nav' href='" .$siteurl. "/vote.php?id=" .$did. "' title='Vote link'>" .$siteurl. "/vote.php?id=" .$did. "</td></tr> <tr><td> </td><td align='left'><input type='submit' name='dok' value='Update'> <input type='submit' name='delok' value='Delete'></td></tr> </table>"; } //======================================================================== Display echo "<form method='post' action='" .curPageURL(). "' style='margin:0px;'>"; If ($sidebar=="Yes") { echo "<table align='center' width='100%'> <tr><td align='left' width='80%' valign='top'>"; } If ($_GET['act']=='add' || $_GET['act']=='see' || $_GET['act']=='login' || $_GET['act']=='register' || $_GET['act']=='settings' || $_GET['act']=='myservers' || $_GET['act']=='minequery' || $_GET['act']=='help') { If ($_GET['act']=='add') { If (!$_SESSION['user']=='') { echo $addsv; } else { echo $login; } } If ($_GET['act']=='login') { If ($_SESSION['user']=='') { echo $login; } else { echo $servers; } } If ($_GET['act']=='register') { If ($_SESSION['user']=='') { echo $register; } else { echo $servers; } } If ($_GET['act']=='see') { If ($exist=='Yes') { echo $details; } else { echo $servers; } } If ($_GET['act']=='settings') { If ($_SESSION['user']=='') { echo $login; } else { echo $settings; } } If ($_GET['act']=='myservers') { echo $servers; } If ($_GET['act']=='minequery') { echo $minequery; } If ($_GET['act']=='help') { echo $help; } } else { echo $servers; } If ($sidebar=="Yes") { echo "</td><td align='right' width='20%' valign='top'> <table align='center' width='100%' class='fancy'> " .$rsidead. " </table> </td></tr> </table>"; } echo "</form>"; include ("./footer.php"); ?> this is where I tried to put pagination in: Code: [Select] If ($_GET['act']=='' || $_GET['act']=='sponsored' || $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers ORDER BY votes DESC") or die (mysql_error()); while($rk_list[] = mysql_fetch_array($result)); If (isSet($username) && $_GET['act']=='myservers') { $result = mysql_query("SELECT * FROM servers WHERE username='$username' ORDER BY id DESC") or die (mysql_error()); } else { If ($_GET['act']=='sponsored') { $result = mysql_query("SELECT * FROM servers WHERE sponsored='Yes' ORDER BY id DESC") or die (mysql_error()); } else { If (isSet($_GET['country'])) { $result = mysql_query("SELECT * FROM servers WHERE country='$_GET[country]' ORDER BY votes DESC") or die (mysql_error()); } else { $result = mysql_query("SELECT * FROM servers ORDER BY $sortby DESC") or die (mysql_error()); } } } $nr = mysql_num_rows($result); If ($nr<='0') { $serverslist = "<tr><td align='center' colspan='6'>There are no servers added yet !</td></tr>"; } else { include ("./minequery.class.php"); $rank = "0"; while($row = mysql_fetch_array($result)){ $data[] = $row; } foreach ($data as $row) { $rank = ($rank + 1); If ($row['banner']=='') { $servername = $row['name']; } else { $servername = "<img src='" .$row['banner']. "' style='width:400px;height:60px' title='Server details'>"; } If ($row['sponsored']=='Yes') { $star = "style='background:url(./images/star.png);background-repeat:no-repeat;'"; } else { $star = ""; } If ($row['mineq']=='Yes') { If (!$row['ip']=='') { $mine = array((Minequery::query($row['ip']))); $onlinep = $mine["0"]["playerCount"]; } else { $onlinep = "<i>n/a</i>"; } } else { $onlinep = "<i>n/a</i>"; } $country = "./flags/" .$row['country']. ".png"; $serverslist .= "<tr><td align='center'>" .(array_search($row, $rk_list) + 1). "</td><td align='center'><a href='./index.php?country=" .$row['country']. "'><img src='" .$country. "' title='" .$row['country']. "' style='width:32px;height:32px;'></a></td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center' " .$star. ">" .$row['ip']. "</td><td align='center'>" .$onlinep. "</td><td align='center'>" .$row['votes']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center' valign='middle' style='height:60px;'><a class='nav' href='./index.php?act=see&id=" .$row['id']. "' title='Server details'>" .$servername. "</a></td><td align='center'><img src='./flags/" .$row['country']. ".ico' title='" .$row['country']. "'> " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td><td align='center'>" .$row['date']. "</td></tr>"; //$serverslist .= "<tr><td align='center'>" .$row['id']. "</td><td align='center'>" .$servername. "</td><td align='center'>" .country_flag($row['ip']). " " .$row['ip']. "</td><td align='center'>" .$row['votes']. "</td></tr>"; } } } /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // 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 ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='./{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ I'm not sure what im doing wrong can anyone help? <?php require_once('upper.php'); // Connects to your Database require_once('database.php'); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $query = "SELECT * FROM events"; $result = mysqli_query($dbc,$query) or die('Not'); $rows = mysqli_num_rows($result); //This is the number of results displayed per page $page_rows = 2; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets range that we will display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $result = mysqli_query($dbc,"SELECT * FROM events $max") or die('Not'); //This is where you display your query results while($row = mysqli_fetch_array( $result)) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<div><table border='0' cellspacing='0' cellpadding='0' width='389'> <tr> <td><img src='images/events_2.png' width='389' height='10'></td> </tr> <tr> <td background='images/events_2_bg.png'> <table border='0' cellspacing='0' width='359'> <tr> <td> <tr> <table width='100%' border='0' cellspacing='0' > <tr> <td rowspan='3'><img src='$Photo' width='80' height='60'></td> <td align='left' valign='top' width='180'>$City</td> <td align='left' valign='top'>$Date</td> </tr> <tr> <td colspan='3' align='left' valign='top'>$Title</td> </tr> <tr> <td colspan='2'><a href='KnowMore.php?EventId=".$row['EventId']."'>Know more </a> / <a href='EventParticipator.php?EventId=".$row['EventId']."'>click here to participate</a></td> </tr> </table> </tr> </tr> </table> </td> </tr> <tr> <td><img src='images/events_2_bottom.png' width='389' height='10' ></td> </tr> </table></div>"; } echo "<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page. if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['pagination.php']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['page_test.php']}?pagenum=$previous'> <-Previous</a> "; } echo $PHP_SELF; //just a spacer echo " ---- "; //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['page_test.php']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['page_test.php']}?pagenum=$last'>Last ->></a> "; } require_once('lower.php'); ?> Quote Hi friends............ I want to paginate my page but it not works properly. It displays first 2 rows but on clicking "Next" nothing happens. It displays error also "Notice: Undefined variable: PHP_SELF in C:\wamp\www\NGOProject\Elite Brigade\pagination.php on line 112" and "Notice: Undefined index: page_test.php in C:\wamp\www\NGOProject\Elite Brigade\pagination.php on line 124"......... I don't know what to do?????? please help me anyone??????? 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? 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"; }?> Hello Please can someone help me, I currently have all working on my friends online shop other than the pagination. When clicking a topic say category - products matching that category show, which is fine only if there is more than say 12 records i need to split it between php pages. Again works fine on the first page but when I click previous or last it ignores the id (category) and lists all the products not only under 'Black' I am really new to PHP so if you can help please could you show me on my code below so I can make sense of it. here's my could for the category :- <a href='shop_online2.php?id=<?php echo($row['id']) ?>'> <?php echo($row['description']) ?></a> <?php } while ($row_cat = mysql_fetch_assoc($cat)); ?> here's my code for the next button :- <? if (!($start>=$record_count-$per_page)) echo " <a href='shop_online2.php?start= $next '>Next</a> "; ?> Hopefully I will only have to add a variable in the last statement, if so could you please show me the correct formatting for this. Hope this makes sense ?? Thanks Marc Hi gurus! Recently i am facing a tiny problem. I want to do is pagination like (<< PREVIOUS | INDEX | NEXT >>). My codes are below. Regards Code: [Select] <?php $SQL = mysql_query("SELECT id FROM blogmaster ORDER BY id DESC"); while($ROW = mysql_fetch_array($SQL)) { $MYARRAY[] = $ROW['id']; } $ARRAYCOUNT = count($MYARRAY); if($MYARRAY[0] != $_GET['id']) { $DESC = $MYARRAY[0] + 1; echo '<a href="/blog/detail.php?id=' .$MYARRAY[$DESC]. '" class="p-link"><< PREV</a> '; } echo '<a href="/blog/index.php" class="p-link">INDEX</a> '; if($MYARRAY[$ARRAYCOUNT] != $_GET['id']) { $ASC = $MYARRAY[$ARRAYCOUNT] - 1; echo '<a href="/blog/detail.php?id=' .$MYARRAY[$ASC]. '" class="p-link">NEXT >></a> '; } ?> Also how can i paginate something like <<PREV | 1 2 3 4 5 | NEXT>> when user reach page #5 and click NEXT link then page number should change <<PREV | 6 7 8 9 10 | NEXT>> 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 --> Using the tutorial from php freaks i was able to get pagination working on my site. How ever there are a few changes id like to make. I would like to have it listed in 2 columns. The other problem that I'm having is when i attempt to add class="nav" to the next page link i get an error. Can a class be used in a php echo? Here's what I have. Code: [Select] <?php session_start(); $rank=$_SESSION['rank']; $loggedinusername=$_SESSION['loggedinusername']; $loggedinuseremail=$_SESSION['loggedinuseremail']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Drink To The Credits</title> <link href="mainstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="background"> <div id="header"> <?php include_once"header.php" ?></div> <div id="content"> <?php include"scripts/connect.php" ; mysql_connect('localhost',$username,$password); @mysql_select_db($database) or trigger_error("SQL", E_USER_ERROR); $sql = "SELECT COUNT(*) FROM movies WHERE type LIKE 'movie'"; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; $rowsperpage = 15; $totalpages = ceil($numrows / $rowsperpage); if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { $currentpage = (int) $_GET['currentpage']; } else { $currentpage = 1; } if ($currentpage > $totalpages) { $currentpage = $totalpages; } if ($currentpage < 1) { $currentpage = 1; } $offset = ($currentpage - 1) * $rowsperpage; $sql = "SELECT title FROM movies ORDER BY title LIMIT $offset, $rowsperpage" ; $result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR); while ($list = mysql_fetch_assoc($result)) { ?> <tr> <td> <a class="nav" href=/rules.php?title=<?php echo urlencode($list['title']); ?>><?php echo $list['title']; ?></a> <br /> <?php } $range = 3; if ($currentpage > 1) { echo " <a href='<?php {$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; $prevpage = $currentpage - 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { if (($x > 0) && ($x <= $totalpages)) { if ($x == $currentpage) { echo " [<b>$x</b>] "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } } } if ($currentpage != $totalpages) { $nextpage = $currentpage + 1; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // built with a tutorial from php freaks ?> </div> <div id="sidecontent"><?php include_once"newmovies.php" ?></div> <div id="footer"> <?php include_once"footer.php" ?></div> </body> </html> Thank you in advance Hello friends. I have a pagination script and there are 3 issues I cant seem to figure out. Here is the code: Code: [Select] <?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. 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! 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? |