TinkPHP+EasyUI,json怎麼條件查詢資料庫?先謝謝了!

來源:互聯網
上載者:User
href:'__URL__/sblog/id/'+idd,


//$json為NULL輸出模板。為1時輸出資料行表資料到前端,格式為Jsonpublic function sblog($json=NULL,$id=NULL){if(!is_int((int)$json)){$json = NULL;}                //dump($id);  這裡能顯示ID為16if($json==1){$sblog = M('Sbly_table');//$id = intval($id);//$info = $sblog->order('id desc')->where('lj_sbid='.$id)->select();$info = $sblog->order('id desc')->select();$new_info = array();foreach($info as $t){if($t['lj_ly_zt']==1){$t['lj_ly_zt'] = '開啟';}else{$t['lj_ly_zt'] = '關閉';}$new_info[] = $t;}echo json_encode($new_info);unset($sblog,$info,$new_info);}else{$this->display();}unset($Public);    }


$json=1時, 輸出如下3條內容:

[{"id":"38","user_id":"1","title":"001","lj_sbid":"16"},{"id":"36","user_id":"1","title":"002","lj_sbid":"18"},
{"id":"34","user_id":"1","title":"003","lj_sbid":"17"}]




前端處理後能正確顯示3行資料,但是我只想要顯示lj_sbid為16的資料,
$info = $sblog->order('id desc')->where('lj_sbid=16')->select();
這樣能正確顯示lj_sbid為16的一條資料,但是這樣:
$info = $sblog->order('id desc')->where('lj_sbid='.$id)->select();
又不能輸出?該怎麼寫才對?先謝謝大家了


回複討論(解決方案)

理論上寫的沒什麼問題,你可以嘗試輸出下$id是什麼值

order應該在where 後邊

$id能輸出16,到底是哪裡錯誤呢?

你要的不是$id的值

模板sql語句 文法有問題

你要的不是$id的值

模板sql語句 文法有問題



$id只是條件,語法錯誤在哪裡?請高手指點一下,謝謝主!

dump($id); 貼出結果

dump($id);

輸出:
string(2) "16"

你不是用 EasyUI 嗎?
string(2) "16" 在哪裡看到的?

TinkPHP+EasyUI

sblog.htm模板輸出的

用 Volist標籤老顯示載入中......,改用Foreach標籤就OK了

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.