Alexhoward Posted March 28, 2008 Share Posted March 28, 2008 Hi Guys, I've modified a search script to display the results the same as my paging script It works lovely, except.... It wont go to the next page! i think it's because it either forgets the search, or wants to search again! Could someone please tell me why? example page (for reference) : www.everyonlinestore.co.uk/testpaging.php Thanks in Advance! <?php include ("banner.php") ?> <html> <body> <form name="form" action="testpaging.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } // WHERE QUERY BUILDER ///// // Split into array of keywords $kw = @explode(" ",$var); // Get number of keywords $x = (!is_array($kw))? "1" : count($kw); // Loop for each keyword adding a where query each time. For($i=0;$i<$x;$i++){ // the current keyword (made safe from mysql_injection), depending on wether the explode() worked or not. $key = ($x==1)? mysql_escape_string($var) : mysql_escape_string($kw[$i]); // Add the where item as an appended array. $where[] = "`keywords` LIKE '%$key%' OR `keywords` LIKE '%$key%'"; } // Get full where query using the array created $where = "WHERE ".implode(" OR ",$where); // --------------- END WHERE BUILDER if (!isset($_GET['start'])) { $_GET['start'] = 0; } if (!isset($_GET['p_f'])) { $_GET['p_f'] = 0; } require "config2.php"; // All database details will be included here $page_name="testpaging.php"; // If you use this code with a different page ( or file ) name then change this $start= $_GET['start']; // To take care global variable if OFF if(!($start > 0)) { // This variable is set to zero for the first page $start = 0; } $eu = ($start -0); $limit = 12; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM links $where"; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); /////// The variable nume above will store the total number of records in the table//// ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// $query=" SELECT * FROM links $where limit $eu, $limit "; $result=mysql_query($query); echo mysql_error(); $numresults=mysql_query($query2); $numrows=mysql_num_rows($numresults); // display wht you searched for echo "<p>You searched for: "" . $var . ""</p>"; // result numbers $a = $start + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $start; echo "<p>Showing results $b to $a of $numrows</p>"; //create table echo "<link href='Images/bkgrnd.css' rel='stylesheet' type='text/css'><table width='100%' border='0'>"; // display the users in table $c = 0; while($row = mysql_fetch_array($result)) { $user2 = html_entity_decode($row['link']); if($c%3 == 0) echo "<tr>"; // If the counter has ticked 5 times, start a new row. echo "<td scope='row' height='150' width='25%' align='center' valign='middle' class='bkgrnd'>$user2</td>"; if($c%3 == 2) echo "</tr>"; // If we're drawing the 6th pic, end this row. $c++; } if($c%5 != 4) echo "</tr>"; // If there isn't a number of pics divisible by 6, end the row echo "</table>"; // end the table ////////////////////////////// End of displaying the table with records //////////////////////// ///// Variables set for advance paging/////////// $p_limit=12; // This should be more than $limit and set to a value for whick links to be breaked $p_f= $_GET['p_f']; // To take care global variable if OFF if(!($p_f > 0)) { // This variable is set to zero for the first page $p_f = 0; } $p_fwd=$p_f+$p_limit; $p_back=$p_f-$p_limit; //////////// End of variables for advance paging /////////////// /////////////// Start the buttom links with Prev and next link with page numbers ///////////////// echo "<table align = 'center' width='80%'><tr><td align='left' width='20%'>"; if($p_f<>0){print "<a href='$page_name?start=$p_back&p_f=$p_back'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align='left' width='10%'>"; //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// if($back >=0 and ($back >=$p_f)) { print "<a href='$page_name?start=$back&p_f=$p_f'><font face='Verdana' size='2'>PREV</font></a>"; } echo "</td><td align='right' width='10%'>"; ///////////// If we are not in the last page then Next link will be displayed. Here we check that ///// if($this1 < $nume and $this1 <($p_f+$p_limit)) { print "<a href='$page_name?start=$next&p_f=$p_f'><font face='Verdana' size='2'>NEXT</font></a>";} echo "</td><td align='right' width='20%'>"; if($p_fwd < $nume){ print "<a href='$page_name?start=$p_fwd&p_f=$p_fwd'><font face='Verdana' size='2'>NEXT</font></a>"; } echo "</td></tr></table>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/98346-search-script-working-but-notsoo-close/ Share on other sites More sharing options...
sasa Posted March 28, 2008 Share Posted March 28, 2008 add &q=$var to your PREV and NEXT links <a href='$page_name?start=$back&p_f=$p_f&q=$var'> Quote Link to comment https://forums.phpfreaks.com/topic/98346-search-script-working-but-notsoo-close/#findComment-503375 Share on other sites More sharing options...
Alexhoward Posted March 28, 2008 Author Share Posted March 28, 2008 nice one! sussed that on the drive home Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/98346-search-script-working-but-notsoo-close/#findComment-503465 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.