Re: Newbie question, Which way is best?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Shawn,

>> My query code-
>>
>> -------SQL query construction block
>>       $query = "SELECT * FROM prods ";
>>       if($catagory != 0){ 
>> //
>> if category != 0
>>          $where="WHERE c = $catagory ";
>>          if ($manu != 0){                                          // 
>> check
>> manu != 0
>>             $and = "AND m = $manu ";
>>             if ($searchstring != 0){
>>                $and = $and."AND description LIKE \"%$searchstring%\" "; 
>> //
>> check like != 0
>>             }
>>          }else{
>>         ...
>> $query=$query.$where.$and.$like
>>
>> -----------
>> Can you please explain your suggestion above in laymans terms. I can't 
>> see
>> what you have in mind. Is it your suggestion to use one script, 
>> containing a
>> from, that calls another script that handles my query construction? That 
>> far
>> I follow you but what happens next?
>>
>>
>>
> What file is this?  is the pagination code in this file also?  If not
> where?  Post you pagination code and this is a simple explanation.
>
> Build your query as you've done and stick it in a session var.  It is
> now available to future calls to this page or other pages.
>
> -Shawn

The above code was included in post to show how query is constructed.

Heres my pagination code.
-------------------
if($page > 1){ // if number of pages > 1 then display 'Previous' button
        $pageprev = $page-1;
   echo("<a href=\"display_products.php?page=$pageprev\"><img 
src=\"btnprevenabled.gif\" ALT=\"Previous\" border=\"0\" ></a> ");
}else{
        echo("<img src=\"btnprevdisnabled.gif\" ALT=\"Previous\"border=\"0\" 
 > ");
}
//----
$numpages = $totalrows / $show; //$show holds number of items to display per 
page
// display a button for each page with current page showing disabled button
for($i = 1; $i <= $numpages; $i++){
   $str1="btn_";
   $str2=$i;
    if($i == $page){
         $str3=$str1.$str2."disabled.gif";
      echo("<img src=$str3 border=\"0\"> ");
    }else{
         $str3=$str1.$str2."_enabled.gif";
            echo("<a href=\"displayproducts.php?page=$i\"><img src=$str3 
border=\"0\" ></a> ");
         }
}
// if last page is less than full
if(($totalrows % $show) != 0){
   $str2=$i;
      if($i == $page){
         $str3=$str1.$str2."disabled.gif";
      echo("<img src=$str3 border=\"0\"> ");//$i ");
        }else{
         $str3=$str1.$str2."enabled.gif";
      echo("<a href=\"displayproducts.php?page=$i\"><img src=$str3 
border=\"0\" ></a> ");//$i</a> ");
        }
}
// Display the enabled or disabled 'Next' button
if(($totalrows - ($show * $page)) > 0){
      //$str3=$str1.$str2."disabled.gif";
        $pagenext =$page+1;
        echo("<a href=\"displayproducts.php?page=$pagenext\"><img 
src=\"btnnextenabled.gif\" border=\"0\" ></a>");//$i</a> ");
}else{
   $pagenext =$page+1;
        echo("<img src=\"btnnextdisabled.gif\" ALT=\"Next\"border=\"0\" > 
");
}
?>
</td></font></tr></table>
---------------

Thanks for sticking with me.

George



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux