php - How to add multiple sql queries to paginaiton dynamically? -


i trying add or connect multiple sql queries dynamically.

i creating pagination script , trying add filter buttons or links in case when user clicks on links, add id sql query , display results.

to better understand saying, show script i'm working on:

below see have 3 links; marketing, automotive, , sports. these links represent filter selections, when 1 clicked 'marketing' the sql query insert marketing 'category=$ids'. works fine, except when want add multiple selections picking 'marketing' , 'sports' , not have 'automotive' display.

is there easy way add multiple ids sql connection instead of one?

i hope makes sense, if need further explanation let me know. on this.

<?php   $ids=$_get['id'];   echo $ids;    $pagen = $_get['page'];   echo $pagen; ?>  <!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>superman</title> <link href="../style.css" rel="stylesheet" type="text/css" />   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script type="text/javascript" >  $(document).ready(function(){  // filter content.         $("a.category").click(function() {          var this_id = $(this).attr('id');         $("#pagination").load('index.php?&id='+ this_id+'&page=1' );      }); }); </script>   <style> .paginate { font-family:arial, helvetica, sans-serif;     padding: 3px;     margin: 3px; }  .paginate {     padding:2px 5px 2px 5px;     margin:2px;     border:1px solid #999;     text-decoration:none;     color: #666; } .paginate a:hover, .paginate a:active {     border: 1px solid #999;     color: #000; } .paginate span.current {     margin: 2px;     padding: 2px 5px 2px 5px;         border: 1px solid #999;          font-weight: bold;         background-color: #999;         color: #fff;     }     .paginate span.disabled {         padding:2px 5px 2px 5px;         margin:2px;         border:1px solid #eee;         color:#ddd;     }      li{         padding:4px;         margin-bottom:3px;         background-color:#bbbecb;         list-style:none;}      ul{margin:6px;     padding:0px;}     </style> </head>  <body> <p>fitler results</p> <br /> <a href="#" class="category" id="marketing">marketing</a>  <a href="#" class="category" id="automotive">automotive</a>  <a href="#" class="category" id="sports">sports</a>  <br /> <br />   <?php     include('connect.php');       $tablename="explore";            $targetpage = "index.php";       $limit = 2;       $query = "select count(*) num $tablename category='$ids'";     $total_pages = mysql_fetch_array(mysql_query($query));     $total_pages = $total_pages[num];      $stages = 3;     $page = mysql_escape_string($_get['page']);     if($page){         $start = ($page - 1) * $limit;      }else{         $start = 0;          }         // page data     //$query1 = "select * $tablename limit $start, $limit";     $query1 = "select * explore category='$ids' order category limit $start, $limit";     $result = mysql_query($query1);      // initial page num setup     if ($page == 0){$page = 1;}     $prev = $page - 1;       $next = $page + 1;                               $lastpage = ceil($total_pages/$limit);           $lastpagem1 = $lastpage - 1;                           $paginate = '';     if($lastpage > 1)     {                $paginate .= "<div class='paginate'>";         // previous         if ($page > 1){             $paginate.= "<a href='$targetpage?page=$prev'>previous</a>";         }else{             $paginate.= "<span class='disabled'>previous</span>";   }            // pages             if ($lastpage < 7 + ($stages * 2))  // not enough pages breaking         {                ($counter = 1; $counter <= $lastpage; $counter++)             {                 if ($counter == $page){                     $paginate.= "<span class='current'>$counter</span>";                 }else{                     $paginate.= "<a href='$targetpage?&id=$ids&page=$counter'>$counter</a>";}                                }         }         elseif($lastpage > 5 + ($stages * 2))   // enough pages hide few?         {             // beginning hide later pages             if($page < 1 + ($stages * 2))                    {                 ($counter = 1; $counter < 4 + ($stages * 2); $counter++)                 {                     if ($counter == $page){                         $paginate.= "<span class='current'>$counter</span>";                     }else{                         $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                                     }                 $paginate.= "...";                 $paginate.= "<a href='$targetpage?page=$lastpagem1'>$lastpagem1</a>";                 $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";                    }             // middle hide front ,             elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))             {                 $paginate.= "<a href='$targetpage?page=1'>1</a>";                 $paginate.= "<a href='$targetpage?page=2'>2</a>";                 $paginate.= "...";                 ($counter = $page - $stages; $counter <= $page + $stages; $counter++)                 {                     if ($counter == $page){                         $paginate.= "<span class='current'>$counter</span>";                     }else{                         $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                                     }                 $paginate.= "...";                 $paginate.= "<a href='$targetpage?page=$lastpagem1'>$lastpagem1</a>";                 $paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";                    }             // end hide pages             else             {                 $paginate.= "<a href='$targetpage?page=1'>1</a>";                 $paginate.= "<a href='$targetpage?page=2'>2</a>";                 $paginate.= "...";                 ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)                 {                     if ($counter == $page){                         $paginate.= "<span class='current'>$counter</span>";                     }else{                         $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}                                     }             }         }                  // next         if ($page < $counter - 1){              $paginate.= "<a href='$targetpage?page=$next'>next</a>";         }else{             $paginate.= "<span class='disabled'>next</span>";             }          $paginate.= "</div>";          }  echo $total_pages.' results';  // pagination  echo $paginate; ?>  <ul id="pagination">  <?php            while($row = mysql_fetch_array($result))         {          echo '<li>'.$row['site_name'].'</li>';          }      ?> </ul>   </body> </html> 

i not sure $ids contain, mysql has in() operator acts or statement ie:

...where category in(1,2,3,4,5)...

so $ids need comma delimited list, whether actual title or id. helps figure out need do.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -