午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    ThinkPHP查詢(xún)語(yǔ)句與關(guān)聯(lián)查詢(xún)用法實(shí)例
    來(lái)源:易賢網(wǎng) 閱讀:5609 次 日期:2014-11-02 10:11:54
    溫馨提示:易賢網(wǎng)小編為您整理了“ThinkPHP查詢(xún)語(yǔ)句與關(guān)聯(lián)查詢(xún)用法實(shí)例”,方便廣大網(wǎng)友查閱!

    易賢網(wǎng)網(wǎng)校上線了!

    >>>點(diǎn)擊進(jìn)入<<<

    網(wǎng)校開(kāi)發(fā)及擁有的課件范圍涉及公務(wù)員、財(cái)會(huì)類(lèi)、外語(yǔ)類(lèi)、外貿(mào)類(lèi)、學(xué)歷類(lèi)、

    職業(yè)資格類(lèi)、計(jì)算機(jī)類(lèi)、建筑工程類(lèi)、等9大類(lèi)考試的在線網(wǎng)絡(luò)培訓(xùn)輔導(dǎo)。

    本文實(shí)例講述了ThinkPHP查詢(xún)語(yǔ)句與關(guān)聯(lián)查詢(xún)用法。分享給大家供大家參考。具體如下:

    在thinkphp框架頁(yè)面中我們可以直接拼寫(xiě)sql查詢(xún)語(yǔ)句來(lái)實(shí)現(xiàn)數(shù)據(jù)庫(kù)查詢(xún)讀寫(xiě)操作,下面就對(duì)此加以實(shí)例說(shuō)明。

    普通查詢(xún)除了字符串查詢(xún)條件外,數(shù)組和對(duì)象方式的查詢(xún)條件是非常常用的,這些是基本查詢(xún)所必須掌握的。

    一、使用數(shù)組作為查詢(xún)條件

    代碼如下:

    $User = M("User"); //實(shí)例化User對(duì)象

    $condition['name'] = 'thinkphp'; // 把查詢(xún)條件傳入查詢(xún)方法

    $User->where($condition)->select();

    二、使用對(duì)象方式來(lái)查詢(xún) 可以使用任何對(duì)象 這里以stdClass內(nèi)置對(duì)象為例

    代碼如下:

    $User = M("User"); // 實(shí)例化User對(duì)象

    // 定義查詢(xún)條件 $condition = new stdClass();

    $condition->name = 'thinkphp'; // 查詢(xún)name的值為thinkphp的記錄

    $User->where($condition)->select(); // 上面的查詢(xún)條件等同于 where('name="thinkphp"') 使用對(duì)象方式查詢(xún)和使用數(shù)組查詢(xún)的效果是相同的,并且是可

    帶where條件的普通查詢(xún)

    1、字符串形式

    代碼如下:

    $user=M('user');

    $list=$user->where('id>5 and id<9')->select();

    $list=$user->where($data)->select();

    2、數(shù)組形式

    代碼如下:

    $user=M('user');

    $list=$user->where(array('username'=>'www.jb51.net'))->select();

    $list=$user->where($data)->select();

    3、對(duì)象形式

    代碼如下:

    $user=M('user');

    $a=new stdClass();

    $a->username='www.jb51.net;

    $list=$user->where($a)->select();

    兩個(gè)表的關(guān)聯(lián)查詢(xún):

    代碼如下:

    $M_shopping = M('Shops');

    $M_product = M('Product');

    $list_shops = $M_shopping->join('as shops left join hr_product as product on shops.product_id = product.p_id')

    ->field('product.p_id,product.p_name,shops.product_amount,shops.product_id')

    ->where("shops.user_cookie='".$_COOKIE['hr_think_userid']."'")

    ->group('shops.id')

    ->select();

    區(qū)間查詢(xún)

    代碼如下:

    $user=M('user');

    $data['id']=array(array('gt',20),array('lt',23),'and');

    $list=$user->where($data)->select();

    組合查詢(xún)

    代碼如下:

    $user=M('user');

    $data['username']='pengyanjie';

    $data['password']=array('eq','pengyanjie');

    $data['id']=array('lt',30);

    $data['_logic']='or';

    $list=$user->where($data)->select();

    dump($list);

    復(fù)合查詢(xún)

    代碼如下:

    $user=M('user');

    $data['username']=array('eq','pengyanjie');

    $data['password']=array('like','p%');

    $data['_logic']='or';

    $where['_complex']=$where;

    $where['id']=array('lt',30);

    $list=$user->where($data)->select();

    三個(gè)數(shù)據(jù)表的關(guān)聯(lián)查詢(xún)

    代碼如下:

    $M_shopping = M('Shops');

    $M_product = M('Product');

    $M_proimg = M('Product_image');

    $list_shops = $M_shopping->join('as shops left join hr_product as product on shops.product_id = product.p_id left join

    hr_product_image as productimgon productimg.p_id = product.p_id')->fiel('productimg.pi_url,product.p_id,product.p_name,shops.product_amount,shops.product_id,product.am_id,

    product.p_procolor,product.p_price,product_amount*p_price as totalone')->where("shops.user_cookie='".$_COOKIE['hr_think_userid']."'")

    ->group('shops.id')->select();

    數(shù)據(jù)表的查詢(xún)條件

    ① 下面的是直接吧查詢(xún)的條件放到了where中,這樣就方便了條件的書(shū)寫(xiě)

    代碼如下:

    $m_test = M("Product");

    $productmeaage = $m_test->where("p_id='$proid'")->select();

    ② 除了上面的方法還有一種是以數(shù)組的方式

    代碼如下:

    $M_product = M('Product');

    $map['pid'] = $proid;

    $p_result = $M_product->where($map)->select();

    希望本文所述對(duì)大家的ThinkPHP框架程序設(shè)計(jì)有所幫助。

    更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

    更多信息請(qǐng)查看網(wǎng)絡(luò)編程
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類(lèi)型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專(zhuān)用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
    咨詢(xún)QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)