Jump to content

Search results into multiple pages


Recommended Posts

Guest D1proball
Ok so I have a search page and I've made it so that when you type in something in the search it brings up a maximun of 15 results by using LIMIT 0,15. I need to know how to make it so that instead of limiting it to 15 I can show all of the results but only have 15 per page.

EX: lets say someone searches something and it has a total of 18 results. I need the results to have 2 pages worth of results. The first page would show the first 15 results and the second page would show the remaining 3 results. If anybody knows how I can do this let me know. Heres the code.

[code]$searchtype=$_POST['searchtype'];
$search=$_POST['search'];
$sorttype=$_POST['sorttype'];
$sortorder=$_POST['sortorder'];

$searchtype2=$_GET['searchtype'];
$search2=$_GET['search'];
$sorttype2=$_GET['sorttype'];
$sortorder2=$_GET['sortorder'];

if($sortorder=="Descending"){
    $sort="desc";}
    else{$sort="";}


if($searchtype=="Name"){
   $query  = "SELECT * FROM neighbor where name like '%$search%' ORDER BY 'name' LIMIT 0, 15";}

elseif($searchtype=="Species"){
   $query  = "SELECT * FROM neighbor where species like '%$search%' ORDER BY 'name' LIMIT 0, 15";}

elseif($searchtype=="Personality"){
   $query  = "SELECT * FROM neighbor where personality like '%$search%' ORDER BY 'name' LIMIT 0, 15";}

elseif($sorttype=="Name"){
   $query  = "SELECT * FROM neighbor ORDER BY name $sort LIMIT 0, 15";}

elseif($sorttype=="Species"){
   $query  = "SELECT * FROM neighbor ORDER BY species $sort LIMIT 0, 15";}

elseif($sorttype=="Personality"){
   $query  = "SELECT * FROM neighbor ORDER BY personality $sort LIMIT 0, 15";}


elseif($searchtype2=="Name"){
   $query  = "SELECT * FROM neighbor where name like '%$search2%' ORDER BY 'name' LIMIT 0, 15";}

elseif($searchtype2=="Species"){
   $query  = "SELECT * FROM neighbor where species like '%$search2%' ORDER BY 'name' LIMIT 0, 15";}

elseif($searchtype2=="Personality"){
   $query  = "SELECT * FROM neighbor where personality like '%$search2%' ORDER BY 'name' LIMIT 0, 15";}

elseif($sorttype2=="Name"){
   $query  = "SELECT * FROM neighbor ORDER BY name $sort LIMIT 0, 15";}

elseif($sorttype2=="Species"){
   $query  = "SELECT * FROM neighbor ORDER BY species $sort LIMIT 0, 15";}

elseif($sorttype2=="Personality"){
   $query  = "SELECT * FROM neighbor ORDER BY personality $sort LIMIT 0, 15";}

else{$query  = "SELECT * FROM neighbor LIMIT 0,15";}



  
  
$result = mysql_query($query);



?>
<br>
<table width="60%" height="1%" border="1" align="center" bordercolor="#003300">
  <tr>
    <td height="27" bgcolor="B5F2B5"><form name="form1" method="post" action="">
        <div align="center">Search:
          <select name="searchtype" id="searchtype">
            <option selected>Name</option>
            <option>Species</option>
            <option>Personality</option>
          </select>
          <input name="search" type="text" id="search">
          <input name="submit" type="submit" id="submit" value="Search">
        </div>
      </form></td>
  </tr>
  <tr>
    <td height="28" bgcolor="B5F2B5"> <form name="form2" method="post" action="">
        <div align="center">Sort:
          <select name="sorttype" id="sorttype">
            <option selected>Name</option>
            <option>Species</option>
            <option>Personality</option>
          </select>
          <select name="sortorder" id="sortorder">
            <option selected>Ascending</option>
            <option>Descending</option>
          </select>
          <input name="submit2" type="submit" id="submit2" value="Sort">
        </div>
      </form></td>
  </tr>
</table><br>
<?
while(list($name,$species,$bday,$gender,$personality,$catchphrase,$picphrase,$image)= mysql_fetch_row($result))
{
print"<center><table width=\"40%\" border=\"1\" bordercolor=\"#006600\" bgcolor=\"#FFFFFF\">
  <tr>
    <td height=\"108\"><p align=\"center\"><img src=\"http://www.acadvocates.com/images/neighbors/$image\" width=\"95\" height=\"85\" align=\"middle\">
      <br><center><b>$name</b></center></td>
  </tr>
  <tr>
    <td height=\"164\"><table width=\"100%\" height=\"157\" border=\"0\" bordercolor=\"#006600\">
        <tr>
          <td width=\"40%\" height=\"11\"><strong><font size=\"-1\">Species</font></strong></td>
          <td width=\"60%\"><font size=\"-1\">$species</font></td>
        </tr>
        <tr>
          <td height=\"11\"><strong><font size=\"-1\">Birthday</font></strong></td>
          <td height=\"11\"><font size=\"-1\">$bday</font></td>
        </tr>
        <tr>
          <td height=\"24\"><strong><font size=\"-1\">Gender</font></strong></td>
          <td height=\"24\"><font size=\"-1\">$gender</font></td>
        </tr>
        <tr>
          <td height=\"24\"><strong><font size=\"-1\">Personality</font></strong></td>
          <td height=\"24\"><font size=\"-1\">$personality</font></td>
        </tr>
        <tr>
          <td height=\"24\"><strong><font size=\"-1\">Catchphrase</font></strong></td>
          <td height=\"24\"><font size=\"-1\">$catchphrase</font></td>
        </tr>
        <tr>
          <td height=\"23\"><strong><font size=\"-1\">Picture Phrase</font></strong></td>
          <td height=\"23\"><font size=\"-1\">$picphrase</font></td>
        </tr>
      </table></td>
  </tr>
</table><br></center>";
}


?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/5542-search-results-into-multiple-pages/
Share on other sites


This is one way also use this link ok.


[!--sizeo:5--][span style=\"font-size:18pt;line-height:100%\"][!--/sizeo--]Pagination[!--sizec--][/span][!--/sizec--]

[a href=\"http://www.phpfreaks.com/quickcode/Pagination/164.php\" target=\"_blank\"]http://www.phpfreaks.com/quickcode/Pagination/164.php[/a]

[code]
if(!isset($page)) $page = 0;

//mysql_query here to get $page_text

$pagearray=split("[NEXTPAGE]", $page_text);

echo "$page_text";

if($page != 0){
    $prevpage = $page - 1;
    echo "<a href="/link_to_previous_page">Previous Page</a>&nbsp;&nbsp;";
}

if($page < count($pagearray) -1) {
    $nextpage = $page + 1;
    echo "<a href="/link_to_next_page">Next Page</a>";
}
[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.