0

Please don't closed really need help for pagination of my category pages. i m using smarty. my main page pagination is working fine. I want same for category pages too. My tables

1. products-(contains image, details). 
2. product_tags-(contains tag, perma) 
3. product_tag_joins-(contains tag_id, product_id)

My category.php code:

This code is working fine showing products according to the category name. please paginate this.

if (@$tag){
$tag = $product->getCategoryByPerma($tag);
if ($tag){
    $tagid = $tag['id'];
    $tag = $tag['tag'];

    $tagproducts = $product->getProductsByCategory($tagid);
    if (!count($tagproducts)){
        $tagproducts = '';
    } else {
    sort($tagproducts);
        foreach($tagproducts as $key => $val){
            @extract($val);
            $description = nl2br(stripslashes($description));
            if (strlen($description)>=220) $description = substr($description,0,220)."...";
            $tagmovies[$key]['description']=$description;
            $tagmovies[$key]['title']=stripslashes($title);
        }
    }
    $smarty->assign("tagproducts",$tagproducts);

}} else {$tag = '';}$seodata['category']=$tag;$smarty->assign("tag",$tag);

AND for getCategoryByPerma:

public function getCategoryByPerma( $perma );
{
    $perma = mysql_real_escape_string( $perma );
    if ( !( $e = mysql_query( "SELECT id,tag FROM product_tags WHERE perma='{$perma}'" ) ) )
    {
        exit( mysql_error( ) );
    }
    if ( mysql_num_rows( $e ) )
    {
        extract( mysql_fetch_array( $e ) );
        return array(
            "id" => $id,
            "tag" => $tag
        );
    }
    return "";
}

AND for getProductsByCategory

public function getProductsByCategory( $tagid )
{
    $tagid = mysql_real_escape_string( $tagid );
    if ( !( $e = mysql_query( "SELECT * FROM products WHERE id IN (SELECT product_id FROM product_tags_join WHERE tag_id='{$tagid}')" ) ) )
    {
        exit( mysql_error( ) );
    }
    $product = array( );
    while ( mysql_num_rows( $e ) && ( $s = mysql_fetch_array( $e ) ) )
    {
        extract( $s );
        $products[$id] = array( );
        $products[$id]['title'] = $title;
        $products[$id]['description'] = $description;
        $products[$id]['thumbnail'] = $thumb;
        $products[$id]['permalink'] = $perma;
    }
    return $products;
}

And here is my paginated main page php code which is working fine. I want same for category pages too.

$maxperpage = $settings->getSetting("maxproductsperpage"); $displaymode = $settings->getSetting("display_mode_product");   if (!@$p) $p = 1;if (((is_array($displaymode)) && (empty($displaymode))) || ($displaymode==0)){
if ($maxperpage){
    $count = $product->getRealProductCount();
    $productlist = $product->getRealProduct($p,$maxperpage);
    if ($seolinks){
        $pagination = $product->getBasicPagination($count,$p,$maxperpage,$baseurl."/products/");
    } else {
        $pagination = $product->getBasicPagination($count,$p,$maxperpage,$baseurl."/index.php?menu=products&p=");
    }
} else {
    $productlist = $product->getRealProducts();
    if ($seolinks){
        $pagination = '<a href="'.$baseurl.'/products">1</a>';
    } else {
        $pagination = '<a href="'.$baseurl.'/index.php?menu=products">1</a>';
    }
}

if (count($productlist)){
    foreach($productlist as $key => $val){
        @extract($val);
        $description = nl2br(stripslashes($description));
        if (strlen($description)>=380) $description = substr($description,0,380)."...";
        $productlist[$key]['description']=$description;
        $productlist[$key]['title']=stripslashes(stripslashes($title));
    }
} else {
    $productlist = '';
}

$smarty->assign("productlist",$productlist);
$smarty->assign("pagination",$pagination);
$smarty->assign("displaymode","0");} 
 else {
    $productlist = '';
}
Wouter J
  • 41,455
  • 15
  • 107
  • 112
boomu
  • 11
  • 5
  • `please paginate this` - Asking nicely still doesn't make it right for people to do your work for you. Only post if you have a specific problem or question. – Boaz Mar 18 '13 at 09:40

1 Answers1

0

below i have listed some links to resources which may get you started on what you are trying to achieve

Smarty Paginate is a pagination plugin that works with the smarty templating engine.

some SO links related to the topic

Pagination (Previous | Next) with Smarty

php-sql-smarty pagination

go through these resources and find some more, then ask question if you get any specific problem/error while implementing the solution

Community
  • 1
  • 1
Rafay
  • 30,950
  • 5
  • 68
  • 101