【问题标题】:pagination php from mysql [duplicate]来自mysql的分页php [重复]
【发布时间】:2013-03-06 14:18:28
【问题描述】:

请不要关闭我的类别页面的分页确实需要帮助。我正在使用聪明的。我的主页分页工作正常。我也希望类别页面也一样。 我的桌子

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 (!@$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 = '';
}

【问题讨论】:

  • please paginate this - 善意地询问仍然不能让人们为你做你的工作。仅在您有特定问题或疑问时发布。

标签: php pagination


【解决方案1】:

下面我列出了一些资源链接,这些链接可以帮助您开始尝试实现的目标

Smarty Paginate 是一个与 smarty 模板引擎配合使用的分页插件。

一些与主题相关的SO链接

Pagination (Previous | Next) with Smarty

php-sql-smarty pagination

浏览这些资源并找到一些more,然后在实施解决方案时询问您是否遇到任何特定问题/错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-31
    • 2014-03-19
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    相关资源
    最近更新 更多