PHP - Help Please Pagination And Results
HI,
Please forgive my inexperience I am new to php and any help is most apreciated. I have a database called liveproj and a table named olde_history. Within the table, Project history is stored. Each project has a unique number ie 10383 etc. I am trying to display the results for an individual project once the project has been selected. The structure of the table is as such: $sql = 'CREATE TABLE IF NOT EXISTS `liveproj`.`olde_history` ( `History_Id` int(6) NOT NULL AUTO_INCREMENT, `History_Project_Id` varchar(10) NOT NULL, `History_Department_Id` varchar(25) NOT NULL, `History_By` varchar(25) DEFAULT NULL, `History_Contact` varchar(25) DEFAULT NULL, `History_Date` varchar(10) NOT NULL, `History_Description` varchar(500) DEFAULT NULL, `History_Action_Owner` varchar(25) DEFAULT NULL, `History_Status_Id` varchar(10) DEFAULT NULL, `History_Action_Date` varchar(10) DEFAULT NULL, `History_Action_Description` varchar(500) DEFAULT NULL, `History_Date_Resolved` varchar(10) DEFAULT NULL, `History_Email` varchar(150) DEFAULT NULL, `History_Minutes` varchar(150) DEFAULT NULL, `History_Visit` varchar(150) DEFAULT NULL, PRIMARY KEY (`History_Id`) )'; A snippet of the table structure I can View all information based on all projects and this works fine althoughh I only wish to display the relevent info for a selected project. The error code I get is as follows: 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 '-10,10' at line 1 My code is: Code: [Select] <!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=utf-8" /> <title>Live Project List</title> <link href="../css/Style.css" rel="stylesheet" type="text/css" /> <style type="text/css"></style> </head> <body id="body"> <div align="center" id="Section">Project History List <div id="apDiv1"> <form id="form1" name="form1" method="post" action=""> <input type="text" name="Search" id="Search" size="20" /> <img src="../Images/search.png" width="24" height="24" align="middle" /> </form> </div> </div> <table class="hovertable"> <tr> <th width="10%">Date:</th> <th width="10%">By:</th> <th width="30%">History Description:</th> <th width="5%">Action Status:</th> <th width="5%">Action Owner:</th> <th width="10%">Action Rqd Date</th> <th width="10%">Action Description:</th> <th width="10%">Date Resolved:</th> <th width="5%">View:</th> <th width="5%">Edit:</th> </tr> <?php ############################################################################### # Start of pagination script ############################################################################### IF (ISSET($_GET['pageno'])) { $pageno = $_GET['pageno']; } ELSE { $pageno = 1; } // if ############################################################################### # 2. Identify how many database rows are available ############################################################################### # This code will count how many rows will satisfy the current query. session_start(); include "../scripts/connect.php"; include "../scripts/Inc/db_lp.php"; //$disc = $_SESSION['Disc']; $quote='"'; $projno2 = $_SESSION['Project']; $projno = "$quote$projno2$quote"; $query = "SELECT count(*) FROM `liveproj` . `olde_history` WHERE `History_Id` = '$projno'"; //$query = "SELECT count(*) FROM `liveproj` . `olde_history` WHERE `History_Id` <> ''"; //WORKING LINE $result = mysql_query($query) or die(mysql_error()); $query_data = MYSQL_FETCH_ROW($result); $numrows = $query_data[0]; PRINT "NUMROWS: $numrows<br>"; ############################################################################### # 3. Calculate number of $lastpage ############################################################################### # This code uses the values in $rows_per_page and $numrows in order to identify the number of the last page. $rows_per_page = 10; ######## Set the ammount of rows you wish to display per page ######### $lastpage = CEIL($numrows/$rows_per_page); ############################################################################### # 4. Ensure that $pageno is within range ############################################################################### # This code checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; IF ($pageno < 1) { $pageno = 1; } ELSEIF ($pageno > $lastpage) { $pageno = $lastpage; } // if ############################################################################### # 5. Construct LIMIT clause ############################################################################### # This code will construct the LIMIT clause for the sql SELECT statement. $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; ############################################################################### # 6. Issue the database query ############################################################################### # Now we can issue the database query and process the result. $query = "SELECT * FROM `liveproj` . `olde_history` $limit"; $result = mysql_query($query) or die(mysql_error()); #... process contents of $result ... WHILE ($row = MYSQL_FETCH_ARRAY($result)) { echo '<tr onmouseover="this.style.backgroundColor=\'#CCCCCC\';" onmouseout="this.style.backgroundColor=\'#ffffff\';"><td width="10%">'; echo $row["History_Date"]; echo "</td>"; echo '<td width="10%" >'; echo $row["History_By"]; echo "</td>"; echo '<td width="30%">'; echo "" . substr($row['History_Description'],0,20) . ".....[Select View To Read More]" ; //echo $row["History_Description"]; echo "</td>"; echo '<td width="5%">'; echo $row["History_Status_Id"]; echo "</td>"; echo '<td width="5%">'; echo $row["History_Action_Owner"]; echo "</td>"; echo '<td width="10%">'; echo $row["History_Action_Date"]; echo "</td>"; echo '<td width="10%">'; //echo $row["History_Action_Description"]; echo "" . substr($row['History_Action_Description'],0,20) . ".....[Select View To Read More]" ; echo "</td>"; echo '<td width="10%">'; echo $row["History_Date_Resolved"]; echo "</td>"; echo '<td width="5%">'; echo "<div class=form>"; echo '<form id="form" name="form" method="post" action="Doc_History_Desc.php" onSubmit="return confirm('; echo '">'; echo '<input type="hidden" name="histid" value="'; echo $row["History_Id"]; echo '"><input type="image"SRC="../Images/Icons/List-View.png" Height="22" Width="22" value="View" alt="submit" class="hidebutton" name="B1">'; //echo '"><input type="submit" value="View" name="B1">'; echo "</form>"; echo "</td>"; echo '<td width="5%">'; echo "<div class=form>"; echo '<form id="form" name="form" method="post" action=".php" onSubmit="return confirm('; echo '">'; echo '<input type="hidden" name="histid" value="'; echo $row["History_Id"]; echo '"><input type="image"SRC="../Images/Icons/List-Edit.png" Height="22" Width="22" value="View" alt="submit" class="hidebutton" name="B1">'; //echo '"><input type="submit" value="View" name="B1">'; echo "</form>"; echo "</td>"; echo "</tr>"; } ?> </table> <p><br /> <br /> </p> <?php ############################################################################### # 7. Construct pagination hyperlinks ############################################################################### # Finally we must construct the hyperlinks which will allow the user to select # other pages. We will start with the links for any previous pages. echo '<div align="center" id="SectionEnd">'; IF ($pageno == 1) { echo "<font size='1' color='#FFFFFF'>FIRST | PREV</font>"; } ELSE { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a>"; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a>"; } // if # Next we inform the user of his current position in the sequence of available pages. echo " <font size='1' color='#FFFFFF'>( Page $pageno of $lastpage )</font> "; # This code will provide the links for any following pages. IF ($pageno == $lastpage) { echo "<font size='1' color='#FFFFFF'>NEXT | LAST</font>"; } ELSE { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a>"; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a>"; } // if echo'<br/>'; echo'<br/>'; echo'</div>'; ############################################################################### # End of pagination script ############################################################################### ?> </body> </html> Thankyou in advance. Similar TutorialsGood Evening, I've been in a trial and error state for the past week trying to figure out how I can put on the pre-made pagination scripts I found on the web, but of no luck. I have just started programming like two weeks ago, and is still trying to understand logics and stuffs so I can get my desired output. So far, everything is doing well except for one - I am really having a hard time to incorporate pagination scripts with my code. To rank myself as a php programmer, I can say I am lower than one, and seemingly, what I want to achieve is an advanced code. Can anyone help me on what pagination code I should try to play with and incorporate with my code? Here's my code so far: <?PHP include("dbconnection.php"); //Include database connection to file $query = "SELECT * FROM records"; if(isset($_POST["btnSearch"])) { $query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' ORDER BY territory ASC LIMIT 0,15" ; $result = mysql_query($query, $connection) or die(mysql_error()); } ?> <!-- Start of table --> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <td> <table width="760" border="0" cellpadding="0" cellspacing="0"> <!-- Table data containing the Asia Logo --> <td width="199" align="center" valign="top"> <a href="login.html"> <img src="asia.gif" alt="" width="152" height="58" border="0" /> </a> </td> <!-- Table data containing Home button --> <td width="176" align="right" valign="bottom"> <a href="main.php"> <img src="Home.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Table data containing View Client button --> <td width="130" align="right" valign="bottom"> <img src="View.jpg" width="104" height="20" border="0"/> </td> <!-- Table data containing the Add Client button --> <td width="146" align="right" valign="bottom"> <a href="add_client.php"> <img src="Add.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Blank table data --> <td width="109" align="right" valign="bottom"> </td> </table> <!-- Table design division and body--> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="3" bgcolor="#1B1C78"> <img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"> <img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> <tr> <td height="500" colspan="2" align="center" valign="top" bgcolor="#F3FAFE"> <!-- Page contents --> <!-- Search Query --> <br> <form name="form" action="view_client.php" method="post"> <table width="351" border="0"> <tr> <td width="137" align="left" valign="middle"> SEARCH RECORD: </td> <td width="144" align="center" valign="middle"> <input type="text" name="search" /> </td> <td width="56" align="left" valign="middle"> <input type="submit" name="btnSearch" value="Search" /> </td> </tr> </table> <br> <!-- End of search query--> <!-- Start of Search Results--> <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="80" align="center" bgcolor="#E0E8F3">Territory</th> <th width="330" align="center" bgcolor="#E0E8F3">Employer</th> <th width="160" align="center" bgcolor="#E0E8F3">Name</th> <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$last_name.", ".$first_name."</td>"; echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>"; echo "</tr>"; } } ?> </table> </form> <!-- End of page --> </td> </tr> </table> </td> <tr> <td height="38"> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white> <a href="disclaimer.html"> <font color="#FFFFFF">Legal Disclaimer</font> </a> </td> <td width="560" align="center" bgcolor="#0076CC"> Copyright © 2006 - 2010 Asia. All rights reserved. </td> </table></td> </tr> </table> Thank you very much, and I am looking forward for your responses. Thanks! I want visitors to be able to sort the results on my Browse Documentaries page by popularity, date, and type. The only way I know how to do this is to create a separate page for each sorting arrangement and provide a link to each page. Is there any way of doing it on a single page?
I am guessing that I can do things like that with Javascript or jQuery. Is that correct?
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. Hey Guys, In this portion of my code I have tried to implement pagination, as the results try to display a page with over 100 mp3's with flash players on teh page, and of course the page just dies. However my attempt at pagination isnt actually working. can anyone help this noob? <? // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = " SELECT val FROM ax_music " . " LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); // print the random numbers while($row = mysql_fetch_array($result)) { echo $row['val'] . '<br>'; } $row2 = mysql_query("SELECT * FROM ax_music ORDER BY 'sort' ASC"); while($row = mysql_fetch_array($row2)){ ?> <tr> <td><?=$row[title];?></td> <td> <embed src= "musicplayer2.swf" quality="high" width="300" height="52" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" flashvars= "valid_sample_rate=true&external_url=./music/<?=$row[mp3];?>" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed> </td> <td> <? if($row[visible] == 0){ echo "<strong>Not Playlisted</strong><br /> <a href=\"index.php?page=musicplayer&showid=$row[id]\">Add To Playlist</a>"; }else{ echo "<strong>Playlisted</strong><br /> <a href=\"index.php?page=musicplayer&hideid=$row[id]\">Remove From Playlist</a>"; } ?> </td> <td><a href="index.php?page=musicplayer&deleteid=<?=$row[id];?>"><strong>Delete</strong></a></td> <td><a href="./music/<?=$row[mp3];?>"><strong>Download</strong></a></td> </tr> <? } ?> </table> Hi All, I have a pagination script that works correctly when a user clicks on a category heading, however when I am using it to try an display search results it does not take into account the set of records to display per page, it just shows all results. <?php echo '<h3>Search Results</h3><br />'; $query = "SELECT count(*) from merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%'"; $row=mysql_fetch_assoc(mysql_query($query)); $total_records = $row['count(*)']; $records_per_page = 5; $total_pages = ceil($total_records / $records_per_page); $page = intval($p); if ($page < 1 || $page > $total_pages) $page = 1; $offset = ($page - 1) * $records_per_page; $limit = " LIMIT $offset, $records_per_page"; $query = mysql_query("SELECT * FROM merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%' ORDER BY m_id DESC") ; echo mysql_error() ; while($row = mysql_fetch_assoc($query)){ $name = $row['name']; $short = $row['short']; $per = $row['percent']; $m_id = $row['m_id']; ?> <div id="cbbox"> <a href="viewm.php?m_id=<?php echo $m_id;?>"> <div class="cbname"> <?php echo $name;?> - Up to <?php echo $per ;?>% Cashback Available </div> <div class="cbimage"> <img src="pimage/<?php echo $name;?>.gif" height="50px" width="100px" /> </div> <div class="cbshort"> <?php echo $short;?> </div> </a> <div class="cbtweet"> <a href="http://twitter.com/home/?status=Get up to <?php echo $per;?> percent Cashback on purchase from <?php echo $name;?> http://goo.gl/PLkp"><img src="images/cbtweet.png" width="90" height="50" alt="Tweet This" /></a> </div></div> <br /><br /> <?php } if($total_records > 5) { for ($i = 1; $i <= $total_pages; $i++) { echo "<a title='page $i p=$i'>Page $i - </a>"; } } ?> </div> if I echo out $total_records it displays the correct amount (7 in the case I am looking at) Any ideas? Hi Everyone,
I have a question about pagination. I have this code that I would like to incorporate into my php file.
This is said code that will be incorporated:
try { // Find out how many items are in the table $totalItems = $databaseHandle->query(' select count(*) from tableName ')->fetchColumn(); // Set how many items per page to display $limit = 10; // find how many pages are needed $totalPages = ceil($totalItems / $limit); // Find out which page we are on $currentPage = min($totalPages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query $offset = ($page - 1) * $limit; // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $total); // "back" link $prevlink = ($page > 1) ? '<a href="?page=1" title="First page">«</a> <a href="?page=' . ($currentPage - 1) . '" title="Previous page">‹</a>' : '<span class="disabled">«</span> <span class="disabled">‹</span>'; // "forward" link $nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next page">›</a> <a href="?page=' . $totalPages . '" title="Last page">»</a>' : '<span class="disabled">›</span> <span class="disabled">»</span>'; // Display the paging information echo '<div id="paging"><p>', $prevlink, ' Page ', $currentPage, ' of ', $totalPages, ' pages, displaying ', $start, '-', $end, ' of ', $totalItems, ' results ', $nextlink, ' </p></div>'; // Get the results. Paged query $stmt = $databaseHandle->prepare(' select * from tableName order by name limit :limit offset :offset '); // Bind the query params $stmt->bindParam(':limit', $limit, PDO:: PARAM_INT); $stmt->bindParam(':offset', $offset, PDO:: PARAM_INT); $stmt->execute(); // Results? if ($stmt->rowCount() > 0) { $stmt->setFetchMode(PDO::FETCH_ASSOC); $iterator = new IteratorIterator($stmt); // Display the results foreach ($iterator as $row) { echo '<p>', $row['name'], '</p>'; } } else { echo '<p>No results could be displayed.</p>'; } } catch (Exception $e) { echo '<p>', $e->getMessage(), '</p>'; }and this is what is in my php file: <html> <head></head> <body> <?php if (!isset($_POST['q'])) { ?> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" /> </form> <?php } else { ?> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search Results</h2> <?php try { // create object // $swish = new Swish('/usr/local/apache/htdocs/swish/index.swish-e'); $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from command-line $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr); ?> Found <?php echo $result->hits; ?> match(es) for '<?php echo $queryStr; ?>'. <?php // iterate over result set // print details for each match while($r = $result->nextResult()) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (sco <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; //echo 'Country: '.$companies[$wvb_number]['country']; ?> </p> <?php } } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } } ?> </body> </html>My question is what would be the best way incorporate this into my php file so that I am able to display a limit number link by page so that not all of the results are listed on the same page? If that is even possible. i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page)
//Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; }The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table>this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?>but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks Edited by jacko_162, 11 January 2015 - 05:43 PM. I've got a page with pagination set up, but I can't figure out where I went wrong with the links at the bottom. When I do a search, it generates the proper number of links, but clicking on the links goes to a page with a whole row of 20 links at the bottom and no results on the page. (my search should show 3 pages with 2 records on each page) I've looked through the tutorial here and one in a book on pagination. Not seeing what's wrong. I'd narrow this down if I knew where it was causing the problem. pagination links are at the very bottom of the code. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>search.html</title></head> <body> <center> <p>The results of your search:</p> <br> </center> require ('databaseconnect.php'); $select = mysql_select_db($db, $con); if(!$select){ die(mysql_error()); } $display = 2; if (isset($_GET['np'])) { $num_pages = $_GET['np']; } else { $data = "SELECT COUNT(*) FROM descriptors LEFT JOIN plantae ON (descriptors.plant_id = plantae.plant_name) WHERE `leaf_shape` LIKE '%$select1%' AND `leaf_venation` LIKE '%$select3%' AND `leaf_margin` LIKE '%$select4%'"; $result = mysql_query ($data); if (!$result) { die("Oops, my query failed. The query is: <br>$data<br>The error is:<br>".mysql_error()); } $row = mysql_fetch_array($result, MYSQL_NUM); // row 41 $num_records = $row[0]; if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } if(isset($_POST[submitted])) { // Now collect all info into $item variable $shape = $_POST['select1']; $color = $_POST['select2']; $vein = $_POST['select3']; $margin = $_POST['select4']; // This will take all info from database where row tutorial is $item and collects it into $data variable row 55 $data = mysql_query("SELECT `descriptors`.* ,`plantae`.* FROM `descriptors` LEFT JOIN `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`) WHERE `leaf_shape` LIKE '%$select1%' AND `leaf_venation` LIKE '%$select3%' AND `leaf_margin` LIKE '%$select4%' ORDER BY `plantae`.`scientific_name` ASC LIMIT $start, $display"); //chs added this in... row 72 echo '<table align="center" cellspacing="0" cellpading-"5"> <tr> <td align="left"><b></b></td> <td align="left"><b></b></td> <td align="left"><b>Leaf margin</b></td> <td align="left"><b>Leaf venation</b></td> </tr> '; // This creates a loop which will repeat itself until there are no more rows to select from the database. We getting the field names and storing them in the $row variable. This makes it easier to echo each field. while($row = mysql_fetch_array($data)){ echo '<tr> <td align="left"> <a href="link.php">View plant</a> </td> <td align="left"> <a href="link.php">unknown link</a> </td> <td align="left">' . $row['scientific_name'] . '</td> <td align="left">' . $row['common_name'] . '</td> <td align="left">' . $row['leaf_shape'] . '</td> </tr>'; } echo '</table>'; } if ($num_pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; // row 100 if ($current_page != 1) { echo '<a href="leafsearch2a.php?s=' . ($start - $display) . '&np=;' . $num_pages . '">Previous</a> '; } for ($i = 1; $i <= $num_pages; $i++) { if($i != $current_page) { echo '<a href="leafsearch2a.php?s=' . (($display * ($i - 1))) . '$np=' . $num_pages . '">' . $i . '</a>'; } else { echo $i . ' '; } } if ($current_page != $num_pages) { echo '<a href="leafsearch2a.php?s=' . ($start + $display) . '$np=' . " " . $num_pages . '"> Next</a>'; } } ?> </body></html> Need help to correct my cording! I want to limited search results by 5 items on one page.
Don't know how correctly to add limit: "limit $page1,5".
When I add it: $sql = "SELECT * FROM data GROUP BY city ORDER BY city limit $page1,5";
it doesn't limit searching result by pages.
Attached Files
search3.php 1.67KB
5 downloads 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. 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'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.. 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?> 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? 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 can't get my head around it, no matter how many tutorials I read.. So would anyone be able to put this code into a pagination of 3 per page? Many Thanks Code: [Select] <?php if(!$_GET['id']) { $query = "SELECT * FROM news where published = '1' ORDER by id DESC"; $result = mysql_query($query) or die(mysql_error()); $news = mysql_fetch_assoc($result); ?> <?php do { ?> <table width="590" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="2"><h2><? echo $news['title']; ?></h2></td> </tr> <tr> <td width="398"><? echo $news['story']; ?></td> <td width="192"><img src="<? echo $news['image']; ?>" alt="<? echo $news['shortstory']; ?>" width="192" height="108" /></td> </tr> <tr> <td colspan="2"><i><br /> Posted by <? echo $news['author']; ?> on <? echo $news['date']; ?></i></td> </tr> </table><br /> <?php } while ($news = mysql_fetch_assoc($result)); } ?> 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? 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? |