1、table()函數
thinkphp中提供了一個table() 函數,具體用法參考以下語句:
- $list=$Demo->table('think_blog blog,think_type type')->where("blog.typeid=type.id and blog.id='$id'")->field('blog.id as id,blog.title,blog.content,type.typename as type')->order('blog.id desc' )->limit(5)->select();
- echo $Demo->getLastSql(); //打印一下SQL語句,查看一下
2、join()函數,看一下代碼:
- $Demo = M('artist');
- $Demo->join('RIGHT JOIN think_work ON think_artist.id = think_work.artist_id' );
- //可以使用INNER JOIN 或者 LEFT JOIN 這里一定要注意表名的前綴!
- echo $Demo->getLastSql(); //打印一下SQL語句,查看一下
3、原生查詢
- $Model = new Model();
- $sql = 'select a.id,a.title,b.content from think_test1 as a, think_test2 as b where a.id=b.id '.$map.' order by a.id '.$sort.' limit '.$p->firstRow.','.$p->listRows;
- $voList = $Model->query($sql);
新聞熱點
疑難解答
圖片精選