How to make search.php with 1-2-3.. navigation?

Discussion in 'PHP' started by alllyc, Oct 10, 2010.

  1. #1
    How to make search.php with 1-2-3.. pagination? I have search.php below. It sows all the related result only in one page. I want it to show 10 results per page and at the bottom write it like this:

    Previous 1 2 3 4 5 6 7 8 9 10 11 Next

    How can I do it? Thanks a lot...

    <?php
    ob_start();
    require("includes/userUtils.php");
    $GLOBALS['show'] =3;
    if($_REQUEST['pageNo']=="")
    {
        $GLOBALS['start'] = 0;
        $_REQUEST['pageNo'] = 1;
    }
    else
    {
        $GLOBALS['start']=($_REQUEST['pageNo']-1) * $GLOBALS['show'];
    }
    switch($_REQUEST['mode'])
         {
                    case 'login':
                                login();
                                break;
                    case 'rate':
                                ratting();
                                break;
                    default:
                                disphtml("main();");
                                break;
         }
    ob_end_flush();
    
    function main()
    {
    $qry_latest_news = "SELECT * FROM ".NEWS." WHERE sports_category_name like '%".htmlentities(trim($_POST['myfield']))."%' OR news_category_name like '%".htmlentities(trim($_POST['myfield']))."%' OR news_title  like '%".htmlentities(trim($_POST['myfield']))."%' OR news_description  like '%".htmlentities(trim($_POST['myfield']))."%' OR news_brief like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY news_upload_date DESC";
    $sql_latest_news = mysql_query($qry_latest_news) or die(mysql_error());
    
    $qry_article = "SELECT * FROM ".ARTICLE." WHERE article_name like '".htmlentities(trim($_POST['myfield']))."%' OR article_title like'".htmlentities(trim($_POST['myfield']))."%' OR article_description  like'".htmlentities(trim($_POST['myfield']))."%' OR article_image like'".htmlentities(trim($_POST['myfield']))."%' ORDER BY article_upload_date DESC";
    $sql_article = mysql_query($qry_article) or die(mysql_error());
    
    $qry_author = "SELECT * FROM ".AUTHOR." WHERE author_title like '%".htmlentities(trim($_POST['myfield']))."%' OR author_name like '%".htmlentities(trim($_POST['myfield']))."%' OR author_description  like '%".htmlentities(trim($_POST['myfield']))."%' OR author_email like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY author_upload_date DESC";
    $sql_author = mysql_query($qry_author) or die(mysql_error());
    
    $qry_videos = "SELECT * FROM ".VIDEO_GALLARY." WHERE video_category_name like '%".htmlentities(trim($_POST['myfield']))."%' OR video_title like '%".htmlentities(trim($_POST['myfield']))."%' OR video_description  like '%".htmlentities(trim($_POST['myfield']))."%' OR artist_name like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY video_upload_date DESC";
    $sql_videos = mysql_query($qry_videos) or die(mysql_error());
    
    $qry_photos = "SELECT * FROM ".PHOTO_GALLARY." WHERE photo_category_name like '%".htmlentities(trim($_POST['myfield']))."%' OR photo_title like '%".htmlentities(trim($_POST['myfield']))."%' OR photo_description like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY photo_upload_date DESC";
    $sql_photos = mysql_query($qry_photos) or die(mysql_error());
    
    $qry_report = "SELECT * FROM ".REPORT." WHERE report_title like '%".htmlentities(trim($_POST['myfield']))."%' OR report_name like '%".htmlentities(trim($_POST['myfield']))."%' OR     report_description like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY report_upload_date DESC";
    $sql_report = mysql_query($qry_report) or die(mysql_error());
    
    $qry_interview = "SELECT * FROM ".INTERVIEW." WHERE interview_name like '%".htmlentities(trim($_POST['myfield']))."%' OR interview_title like '%".htmlentities(trim($_POST['myfield']))."%' OR     interview_description like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY interview_upload_date DESC";
    $sql_interview = mysql_query($qry_interview) or die(mysql_error());
    
    $qry_banner = "SELECT * FROM ".BANNER." WHERE banner_menu like '%".htmlentities(trim($_POST['myfield']))."%' OR banner_heading like '%".htmlentities(trim($_POST['myfield']))."%' OR banner_title like '%".htmlentities(trim($_POST['myfield']))."%' OR     banner_description like '%".htmlentities(trim($_POST['myfield']))."%' ORDER BY banner_upload_date DESC";
    $sql_banner = mysql_query($qry_banner) or die(mysql_error());
    ?>
    <div id="main_topopt">
        <div id="gall_nm1here"><a href="index.php">Anasayfa</a></div>
        <div id="gall_nm2here"><a href="#">Search</a></div>
    </div>
    <div id="mainsingle_add_top">
          <div id="">
            <br />
    <form name="frm_opts" action="<?php basename($_SERVER['PHP_SELF'])?>" method="post" >
    <input type="hidden" name="mode" value="">
    <input type="hidden" name="pageNo" value="<?php $_POST[pageNo]?>">
    <input type="hidden" name="url" value="<?php $_SERVER['PHP_SELF']?>">
    <input type="hidden" name="hold_page" value="">
    </form>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <?php
      if(mysql_num_rows($sql_latest_news)>0){
      while($row_latest_news = mysql_fetch_array($sql_latest_news)){?>
      <tr>
        <td valign="top"><a href="latest_news.php?news_id=<?=$row_latest_news['news_id']?>"><img src="admin/news_images/<?=$row_latest_news['news_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_latest_news['news_upload_date']))?> <?=$row_latest_news['news_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="latest_news.php?news_id=<?=$row_latest_news['news_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_latest_news['news_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_latest_news['news_description']) { if(strlen($row_latest_news['news_description'])>68) echo substr(stripslashes($row_latest_news['news_description']),0,140); else echo stripslashes($row_latest_news['news_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>
      
       <?php
      if(mysql_num_rows($sql_article)>0){
      while($row_article = mysql_fetch_array($sql_article)){?>
      <tr>
        <td valign="top"><a href="article.php?article_id=<?=$row_article['article_id']?>"><img src="admin/article_images/<?php if($row_article['article_image']){echo $row_article['article_image']; } else echo "no_image.jpg";?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_article['article_upload_date']))?> <?=$row_article['article_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="article.php?article_id=<?=$row_article['article_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_article['article_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_article['article_description']) { if(strlen($row_article['article_description'])>68) echo substr(stripslashes($row_article['article_description']),0,140); else echo stripslashes($row_article['article_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>
      
       <?php
      if(mysql_num_rows($sql_author)>0){
      while($row_author = mysql_fetch_array($sql_author)){?>
      <tr>
        <td valign="top"><a href="author.php?author_id=<?=$row_author['author_id']?>"><img src="admin/author_images/<?=$row_author['author_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_author['author_upload_date']))?> <?=$row_author['author_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="author.php?author_id=<?=$row_author['author_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_author['author_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_author['author_description']) { if(strlen($row_author['author_description'])>68) echo substr(stripslashes($row_author['author_description']),0,140); else echo stripslashes($row_author['author_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>
      
      <?php
      if(mysql_num_rows($sql_videos)>0){
      while($row_videos = mysql_fetch_array($sql_videos)){?>
      <tr>
        <td valign="top"><a href="video.php?video_id=<?=$row_videos['video_id']?>"><img src="admin/video_gallery/<?=$row_videos['video_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_videos['video_upload_date']))?> <?=$row_videos['video_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="video.php?video_id=<?=$row_videos['video_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_videos['video_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_videos['video_description']) { if(strlen($row_videos['video_description'])>68) echo substr(stripslashes($row_videos['video_description']),0,140); else echo stripslashes($row_videos['video_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>
      
       <?php
      if(mysql_num_rows($sql_photos)>0){
      while($row_photos = mysql_fetch_array($sql_photos)){?>
      <tr>
        <td valign="top"><a href="photo.php?photo_id=<?=$row_photos['photo_id']?>"><img src="admin/photo_gallery/<?=$row_photos['photo_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_photos['photo_upload_date']))?> <?=$row_photos['photo_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="photo.php?photo_id=<?=$row_photos['photo_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_photos['photo_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_photos['photo_description']) { if(strlen($row_photos['photo_description'])>68) echo substr(stripslashes($row_photos['photo_description']),0,140); else echo stripslashes($row_photos['photo_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>
       
       <?php
      if(mysql_num_rows($sql_report)>0){
      while($row_report = mysql_fetch_array($sql_report)){?>
      <tr>
        <td><a href="report.php?report_id=<?=$row_report['report_id']?>"><img src="admin/report_images/<?=$row_report['report_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_report['report_upload_date']))?> <?=$row_report['report_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="report.php?report_id=<?=$row_report['report_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_report['report_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_report['report_description']) { if(strlen($row_report['report_description'])>68) echo substr(stripslashes($row_report['report_description']),0,140); else echo stripslashes($row_report['report_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>
        
       <?php
      if(mysql_num_rows($sql_interview)>0){
      while($row_interview = mysql_fetch_array($sql_interview)){?>
      <tr>
        <td valign="top"><a href="interview.php?interview_id=<?=$row_interview['interview_id']?>"><img src="admin/interview_images/<?=$row_interview['interview_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_interview['interview_upload_date']))?> <?=$row_interview['interview_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="interview.php?interview_id=<?=$row_interview['interview_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_interview['interview_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_interview['interview_description']) { if(strlen($row_interview['interview_description'])>68) echo substr(stripslashes($row_interview['interview_description']),0,140); else echo stripslashes($row_interview['interview_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>    
      
      <?php
      if(mysql_num_rows($sql_banner)>0){
      while($row_banner = mysql_fetch_array($sql_banner)){?>
      <tr>
        <td valign="top"><a href="banner.php?banner_id=<?=$row_banner['banner_id']?>"><img src="admin/banner_images/<?=$row_banner['banner_image']?>" height="70" width="140" /></a></td>
        <td width="2%">&nbsp;</td>
        <td valign="top">
        <table border="0" cellpadding="0" cellpadding="0" width="100%">
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:11px; color:#82A7B9;"><?=date("d.m.Y",strtotime($row_banner['banner_upload_date']))?> <?=$row_banner['banner_upload_time']?><td>
          </tr>
          <tr>
            <td><a href="banner.php?banner_id=<?=$row_banner['banner_id']?>"><span  style="font-family:Arial; font-size:13px; color:#023E5A; font-weight:bold;"><?=$row_banner['banner_title']?><td>
          </tr>
          <tr>
            <td style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#454545;"><?php if($row_banner['banner_description']) { if(strlen($row_banner['banner_description'])>68) echo substr(stripslashes($row_banner['banner_description']),0,140); else echo stripslashes($row_banner['banner_description']);} else {echo "<br>No information Available";}?><td>
          </tr>
        </table>
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <? } } ?>    
        
        <?php  
        if($count_user>0 && $count_user > $GLOBALS['show'])    
        {
        ?>
        <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><?php pagination($count_user,"frm_opts");?></td>
        </tr>
        <?php
        }
        ?> 
    </table>
        
    </div>
          </div>
    <?php
    }
    ?>
    Code (markup):
     
    alllyc, Oct 10, 2010 IP
  2. Zeh.

    Zeh. Peon

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use "LIMIT X,Y" in your SQL, and combine it with $_GET.

    SELECT ... LIMIT 0 , 10 will give you 10 first entries.
    So:
    $page = (isset($_GET['page']) && $_GET['page'] > 1) ? preg_replace('/[^0-9]/', '', $_GET['page']) : 1;
    Then:
    SELECT ... LIMIT $page , 10

    Will show page entries...

    Something like that :p
     
    Zeh., Oct 10, 2010 IP