2013-03-18 77 views
0

請不要關閉真的需要我的分類頁面的分頁幫助。我使用smarty。我的主頁分頁工作正常。我也希望類別頁面也一樣。 我的表來自mysql的分頁php

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

我category.php代碼:

此代碼是根據類別名稱做工精細顯示產品。請分頁。

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); 

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 ""; 
} 

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; 
} 

在此可以是工作的罰款我分頁主網頁的PHP代碼。我也希望類別頁面也一樣。

$maxperpage = $settings->getSetting("maxproductsperpage"); $displaymode = $settings->getSetting("display_mode_product"); if ([email protected]$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 = ''; 
} 
+0

'請分頁此 - - 很好地問好仍然不適合人們爲你做你的工作。只有在有特定問題或問題時才發佈。 – Boaz 2013-03-18 09:40:31

回答