Hi, I am currently trying to work on a multi search post method on my php script and incorporate with the pagination script too.

At the moment, my single post method works well with the pagination script. However when i tried to add another search query where user is able to search either by the 1st or the 2nd search queries on its own or search both at the same time to get a more define result, the pagination script doesnt seem to work well. Im not sure if i had done anything wrong with it. Could someone help me to have a look.

$val_d = ''; $val_sub='';
 if ($_POST['device_search']){ $val_d = $_POST['device_search'];}
 else if ($_GET['search']){ $val_d = urldecode($_GET['search']); }

if ($_POST['subconsite']){ $val_sub = $_POST['subconsite'];}
 else if ($_GET['search']){ $val_sub = urldecode($_GET['search']); } 

if (trim($val_d) != '' && trim($val_sub) != ''){ 

    $sql = "select * from wsdevice"; 
    if (trim($val_d) != ''){  
        $sql .= " where wsdevice_num like '%" . trim($val_d) . "%' "; 
        $where = true; 
    } 
    if (trim($val_sub) != ''){ 
        if (!$where){  
            $sql .= " where subcon_site like '%" . trim($val_sub) . "%' "; 
        } 
        else { 
             $sql = str_replace("where ", "where (", $sql); 
             $sql .= " and subcon_site like '%" . trim($val_sub) . "%') or (wsdevice_num like '%" . trim($val_d) . "%' or subcon_site like '%" . trim($val_sub) . "%')";  
        } 
} 
else { 
    die("NO SEARCH TERMS"); 
} 
 
 $results1 = mysql_query($sql) or die (mysql_error()); 
 
   $pagenum = $_GET["pagenum"];
   echo "<center>";
   //This checks to see if there is a page number. If not, it will set it to page 1 
   if (!(isset($pagenum))) 
   { 
   $pagenum = 1; 
   } 
 $numrows = mysql_num_rows($results1);  
 $page_rows = 20; //This is the number of results displayed per page 
 $last = ceil($numrows/$page_rows); //This tells us the page number of our last page 
 if ($pagenum < 1) //this makes sure the page number isn't below one, or more than our maximum pages 
 { 
 $pagenum = 1; 
 } 
 elseif ($pagenum > $last) 
 { 
 $pagenum = $last; 
 } 
 $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query 
 
 $sql = "select * from wsdevice"; 
    if (trim($val_d) != ''){  
        $sql .= " where wsdevice_num like '%" . trim($val_d) . "%' $max"; 
        $where = true; 
    } 
    if (trim($val_sub) != ''){ 
        if (!$where){  
            $sql .= " where subcon_site like '%" . trim($val_sub) . "%' $max"; 
        } 
        else { 
             $sql = str_replace("where ", "where (", $sql); 
             $sql .= " and subcon_site like '%" . trim($val_sub) . "%' $max) or (wsdevice_num like '%" . trim($val_d) . "%' or subcon_site like '%" . trim($val_sub) . "%' $max)";  
        } 
} 
else { 
    die("NO SEARCH TERMS"); 
} 
 $results = mysql_query($sql) or die ("Wrong Device number!".mysql_error());
 
// This is where i output my results
 include "WSsearchtable.php";
 
echo "<br><br><center>Page $pagenum of $last<br><br>"; // This shows the user what page they are on, and the total number of pages
 if($pagenum>1)
 {
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&search=" . urlencode($val_d) . " .+. " . urlencode($val_sub) . "'>First</a> ";
 $previous = $pagenum-1;
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&search=" . urlencode($val_d) . " .+. " . urlencode($val_sub) . "'><<</a>&nbsp; ";
 } 
 //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['PHP_SELF']}?pagenum=$next&search=" . urlencode($val_d) . " .+. " . urlencode($val_sub) . "'>>></a> ";
 echo " ";
 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&search=" . urlencode($val_d) . " .+. " . urlencode($val_sub) . "'>Last</a> ";  

 } 
 
 }

Hi i had managed to modify some part of the script and it worked to a certain extend. this script works only when 2 queries were keyed in togehter to show the results, but the results shown were the whole results from the database. What i want is to show the search queries results and shown them in pages if the results are alot. this script however cannot allow me to query 1 search but i would like the the user to search either by both entries or by a single entry search. Will be grateful if someone could assist me here.. Cheers

code i modified:

$val_d   = '' ;
$val_sub = '';

 if ($_POST['device_search']){ $val_d = $_POST['device_search']; }
 else if ($_GET['search']){ $val_d = urldecode($_GET['search']); }
	else{ DIE ("No such value!"); } 
 
 if ($_POST['getsearch']){ $val_sub = $_POST['getsearch']; }
 else if ($_GET['getsearch']){ $val_sub = urldecode($_GET['getsearch']); }
	else{ DIE ("Please key in the right value!");}
.
.
.
.

if($pagenum>1)
	 {
	 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&search=" . urldecode($val_d) . "&getsearch=". urldecode($val_sub) . "'>First</a> ";
	 $previous = $pagenum-1;
	 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&search=" . urldecode($val_d) . "&getsearch=". urldecode($val_sub) . "'><<</a>&nbsp; ";
	 } 
	 //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['PHP_SELF']}?pagenum=$next&search=" . urldecode($val_d) . "&getsearch=". urldecode($val_sub) . "'>>></a> ";
	 echo " ";
	 echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&search=" . urldecode($val_d) . "&getsearch=". urldecode($val_sub) . "'>Last</a> ";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.