search
HomeBackend DevelopmentPHP Tutorial大侠求助!Thinkphp 如何输出指定值数据

大侠求助!表items有一字段cate_id,我只想输出cate_id=11的数据,具体应该怎么做呢?在网上查阅了好多资料,Thinkphp的开发文档也看了,没有这方面的介绍,求助了
个人感觉主要是$item_mod = m( "items" );这段决定输出数据,但怎么只输出cate_id=11时的数据还请大虾帮助!

<?phpclass shijiuAction extends frontendAction{    public function _initialize( )    {        parent::_initialize( );        $this->_mod = d( "items" );        $this->_cate_mod = d( "items_cate" );    }    public function index( )    {        $month = mktime( 0, 0, 0, date( "m" ), 1, date( "Y" ) );        $sign_log_mod = m( "sign_log" );        $map['uid'] = $this->visitor->info['id'];        $map['sign_date'] = array(            "egt",            $month        );        $sign_info = $sign_log_mod->field( "id,uid,username,sign_date" )->where( $map )->select( );        foreach ( $sign_info as $info )        {            $day = date( "d", $info['sign_date'] );            $sign[$day] = $info;        }        $order = "ordid asc ";        $sort = $this->_get( "sort", "trim", "hot" );        $status = $this->_get( "status", "trim", "all" );        switch ( $sort )        {        case "new" :            $order .= ", coupon_start_time DESC";            break;        case "price" :            $order .= ", price DESC";            break;        case "hot" :            $order .= ", volume DESC";        }        switch ( $status )        {        case "all" :            $where['status'] = "underway";            break;        case "underway" :            $where['status'] = "underway";            break;        case "sellout" :            $where['status'] = "sellout";        }        $where['pass'] = "1";        $index_info['sort'] = $sort;        $index_info['status'] = $status;        $page_size = c( "ftx_index_page_size" );        $p = $this->_get( "p", "intval", 1 );        $index_info['p'] = $p;        $start = $page_size * ( $p - 1 );        $item_mod = m( "items" );        $items_list = $item_mod->where( $where )->order( $order )->limit( $start.",".$page_size )->select( );        $items = array( );        foreach ( $items_list as $key => $val )        {            $items[$key] = $val;            $items[$key]['class'] = $this->_mod->status( $val['status'], $val['coupon_start_time'], $val['coupon_end_time'] );        }        f( "items_list", $items );        $this->assign( "items_list", $items );        $this->assign( "index_info", $index_info );        $count = $item_mod->where( $where )->count( );        $pager = $this->_pager( $count, $page_size );        $this->assign( "page", $pager->fshow( ) );        $this->assign( "total_item", $count );        if ( FALSE === ( $cate_list = f( "cate_list" ) ) )        {            $cate_list = d( "items_cate" )->cate_cache( );        }        $this->assign( "cate_list", $cate_list );        $item_comment_mod = m( "items_comment" );        $comm_map['status'] = "1";        $comment_list = $item_comment_mod->where( $comm_map )->order( "add_time DESC" )->limit( "0,10" )->select( );        $this->assign( "comment_list", $comment_list );        $this->assign( "nav_curr", "shijiu" );        $this->_config_seo( c( "ftx_seo_config.index" ) );        $this->display( );    }    public function so( )    {        $sort = $this->_get( "sort", "trim", "hot" );        $status = $this->_get( "status", "trim", "all" );        $cid = $this->_get( "cid", "trim" );        $k = $this->_get( "k", "trim" );        $order = "ordid asc ";        switch ( $sort )        {        case "new" :            $order .= ", coupon_start_time DESC";            break;        case "price" :            $order .= ", price DESC";        }        switch ( $status )        {        case "all" :            $where['status'] = "underway";            break;        case "underway" :            $where['status'] = "underway";            break;        case "sellout" :            $where['status'] = "sellout";        }        $where['title'] = array(            "like",            "%".$k."%"        );        $this->assign( "k", $k );        if ( $cid )        {            $id_arr = $this->_cate_mod->get_child_ids( $cid, TRUE );            $map['cate_id'] = array(                "IN",                $id_arr            );            $spid = $this->_cate_mod->where( array(                "id" => $cate_id            ) )->getField( "spid" );            if ( $spid == 0 )            {                $spid = $cid;            }            else            {                $spid .= $cid;            }            $this->assign( "cid", $cid );        }        $where['pass'] = "1";        $index_info['sort'] = $sort;        $index_info['status'] = $status;        $page_size = c( "ftx_index_page_size" );        $p = $this->_get( "p", "intval", 1 );        $index_info['p'] = $p;        $start = $page_size * ( $p - 1 );        $item_mod = m( "items" );        $items_list = $item_mod->where( $where )->order( $order )->limit( $start.",".$page_size )->select( );        $items = array( );        foreach ( $items_list as $key => $val )        {            $items[$key] = $val;            $items[$key]['class'] = $this->_mod->status( $val['status'], $val['coupon_start_time'], $val['coupon_end_time'] );        }        f( "items_list", $items );        $this->assign( "items_list", $items );        $this->assign( "index_info", $index_info );        $count = $item_mod->where( $where )->count( );        $pager = $this->_pager( $count, $page_size );        $this->assign( "page", $pager->fshow( ) );        $this->assign( "total_item", $count );        if ( FALSE === ( $cate_list = f( "cate_list" ) ) )        {            $cate_list = d( "items_cate" )->cate_cache( );        }        $this->assign( "cate_list", $cate_list );        $item_comment_mod = m( "items_comment" );        $comment_list = $item_comment_mod->order( "id DESC" )->limit( "0,10" )->select( );        $this->assign( "comment_list", $comment_list );        $this->assign( "nav_curr", "shijiu" );        $this->_config_seo( );        $this->display( );    }    public function shortcut( )    {        $Shortcut = "[InternetShortcut] \r\n\t\tURL=".__ROOT__." \r\n\t\tIDList= \r\n\t\t[{000214A0-0000-0000-C000-000000000046}] \r\n\t\tProp3=19,2 \r\n\t\t";        header( "Content-type: application/octet-stream" );        header( "Content-Disposition: attachment; filename=".c( "ftx_site_name" ).".url;" );        echo $Shortcut;    }    public function cate( )    {        $cid = $this->_get( "cid", "trim" );        $sort = $this->_get( "sort", "trim", "hot" );        $status = $this->_get( "status", "trim", "all" );        $order = "ordid asc ";        switch ( $sort )        {        case "new" :            $order .= ", coupon_start_time DESC";            break;        case "price" :            $order .= ", price DESC";        }        switch ( $status )        {        case "all" :            $map['status'] = "underway";            break;        case "underway" :            $map['status'] = "underway";            break;        case "sellout" :            $map['status'] = "sellout";        }        $id_arr = $this->_cate_mod->get_child_ids( $cid, TRUE );        $map['cate_id'] = array(            "IN",            $id_arr        );        $spid = $this->_cate_mod->where( array(            "id" => $cate_id        ) )->getField( "spid" );        if ( $spid == 0 )        {            $spid = $cid;        }        else        {            $spid .= $cid;        }        $this->assign( "cid", $cid );        $map['pass'] = "1";        $index_info['sort'] = $sort;        $index_info['status'] = $status;        $index_info['cid'] = $cid;        $page_size = c( "ftx_index_page_size" );        $p = $this->_get( "p", "intval", 1 );        $index_info['p'] = $p;        $start = $page_size * ( $p - 1 );        $item_mod = m( "items" );        $items_list = $item_mod->where( $map )->order( $order )->limit( $start.",".$page_size )->select( );        $items = array( );        foreach ( $items_list as $key => $val )        {            $items[$key] = $val;            $items[$key]['class'] = $this->_mod->status( $val['status'], $val['coupon_start_time'], $val['coupon_end_time'] );        }        f( "items_list", $items );        $this->assign( "items_list", $items );        $this->assign( "index_info", $index_info );        $count = $item_mod->where( $map )->count( );        $pager = $this->_pager( $count, $page_size );        $this->assign( "page", $pager->fshow( ) );        $this->assign( "total_item", $count );        if ( FALSE === ( $cate_list = f( "cate_list" ) ) )        {            $cate_list = d( "items_cate" )->cate_cache( );        }        $this->assign( "cate_list", $cate_list );        $item_comment_mod = m( "items_comment" );        $comm_map['status'] = "1";        $comment_list = $item_comment_mod->where( $comm_map )->order( "add_time DESC" )->limit( "0,10" )->select( );        $this->assign( "comment_list", $comment_list );        $this->assign( "nav_curr", "shijiu" );        $cate = d( "items_cate" )->where( array(            "id" => $cid        ) )->find( );        $this->_config_seo( c( "ftx_seo_config.cate" ), array(            "cate_name" => $cate['name'],            "seo_title" => $cate['seo_title'],            "seo_keywords" => $cate['seo_keys'],            "seo_description" => $cate['seo_desc']        ) );        $this->display( );    }}?>


回复讨论(解决方案)

$item_mod = m( "items" );前面加入$map['cate_id'] = 11;就可以了
不知道楼主要的是不是这个结果,希望对你有帮助。

或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据

或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据 我就是想输出cate_id = 11 的数据

引用 2 楼 nowphp 的回复:或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据我就是想输出cate_id = 11 的数据 恩,是的,楼上的方法可以。

引用 3 楼 zhouang1989 的回复:引用 2 楼 nowphp 的回复:或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据我就是想输出cate_id = 11 的数据恩,是的,楼上的方法可以。
好的谢谢啦哈  我试试去  好人一生平安

或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据

如果要输出cate_id 不等于 11的值应该怎么表达啊

引用 2 楼 nowphp 的回复:或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据

如果要输出cate_id 不等于 11的值应该怎么表达啊
 //你要输出的数据

引用 6 楼 zhouang1989 的回复:引用 2 楼 nowphp 的回复:或者你要在模板页面也可以这样,
在循环items_list的里面加入: //你要输出的数据

如果要输出cate_id 不等于 11的值应该怎么表达啊
……
看了下开发文档找到了 谢谢啦 http://www.thinkphp.cn/info/115.html

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),