Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi all
i have php page that i want to apply paging on it , but there is a problem, when i choose page no 2 for example , it has no sense and there is no effect in displaying new data. plus to this that i have two drop down list , when i change the page no , the selected items of these list go the default form not to the selected i have made.
here you are my code , any help please as i don't know php well

PHP
if(isset ($_GET['kat']))
          {
          $subkat=$_GET['kat'];
          $mainkat=$_GET['mainkat'];
          $qmainkat="where maincategory='$mainkat'"; 
          $qkat=$qmainkat." and category='$subkat'";
          echo "<br>[<a href='adm_shop_add.php'>">ADD NEW</a>]";
          
          
          
          $qsh="select * from shop_item $qkat order by postdate desc ";
          $rs_sh=@mysql_query($qsh);
          $ada_sh=@mysql_num_rows($rs_sh);
          if ($ada_sh>0){ 
          if(isset($_GET['page']))
          {
           $pageNum = $_GET['page'];
          }
          else
          {
          $pageNum = 1;
          }
          $offset = ($pageNum - 1) * $rowsPerPage;
          $result=@mysql_num_rows(@mysql_query("select id from shop_item $qkat"));
       
          $query   = "SELECT COUNT(id) AS numrows from shop_item $qkat ";                      
          $result  = mysql_query($query) or die('Error, query failed');
          $row     = mysql_fetch_array($result, MYSQL_ASSOC);
          
          
          $numrows = $row['numrows'];
          
          
          $maxPage = ceil($numrows/$rowsPerPage);
            
          
          $self = $_SERVER['PHP_SELF'];
          $nav  = '';
          for($page = 1; $page <= $maxPage; $page++)
          {
            if ($page == $pageNum)
            {
            $nav .= " $page "; // no need to create a link to current page
            }
            else
            {
             $nav .= " <a href=\"$self?page=$page\">$page</a> ";
            }
         }
         // print the navigation link
         echo $first . $prev . $nav . $next . $last;        
          
          echo "<table border=0 cellpadding=8 cellspacing=8 >";
          echo "<tr>";
          while ($ro_sh=@mysql_fetch_array($rs_sh))
          {
          $row++;
          echo "<td valign=top align=center >";
         if (!empty($ro_sh[picture]))
         {
            echo "<img src='".$ro_sh[picture]."' border=0 width=120>";
         }         
         echo "</td>";
         echo "<td valign=top >";
         $kategoriname=@mysql_result(@mysql_query("select name from shop_kat where id='$ro_sh[category]'"),0,0);
         echo "".$ro_sh[title]."";
         echo "<br><small>".$ro_sh[description];    
         
         echo "</td>";
          echo "</tr>";
          echo "<tr>";
          }
          echo "</tr>";        
          echo "</table>";
          
          }
          }


thanks
Posted

1 solution

XML
may be this is helpful for your


<a href="http://www.9lessons.info/2009/09/pagination-with-jquery-mysql-and-php.html"> link </a>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900