SELECT a.bulletinId,a.title,a.content,b.userName,a.createTime FROM sp_Bulletin a left outer join sp_user b on a.userid=b.userId
ThinkPHP里面怎么写?
(普通查询然后分页)$list=$Bulletin->limit($p->firstRow.','.$p->listRows)->order('bulletinId asc')->findAll();
得到的是
protected 'queryStr' => string 'SELECT * FROM `sp_bulletin` ORDER BY bulletinId asc LIMIT 30,5 ' (length=63)
有人推荐用realtion做,在自己尝试的写了一个
但是不成功
我发一下我的Model类
BulletinModel.class.php
<?php
class BulletinModel extends Model
{
    protected $_validate =array(
        array('title','require','标题必须!',1),
        array('content','require','内容必须'),
        array('title','','标题已经存在',0,'unique',self::MODEL_INSERT),
        );
    protected $_auto=array(
        array('userId','1',self::MODEL_INSERT),
        array('createTime','time',1,'function'),
        );
}
?>
UserModel.class.php
<?php
class UserModel extends Model{
}
?>求帮助,

解决方案 »

  1.   

    $model = new Model();$model->query($sql);可以用query()执行原生态的sql 语句
      

  2.   

    三个数据表的关联查询$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 productimg on productimg.p_id = product.p_id')->field('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();数据表的查询条件1:下面的是直接吧查询的条件放到了where中,这样就方便了条件的书写  $m_test = M("Product");  $productmeaage = $m_test->where("p_id='$proid'")->select();2:除了上面的方法还有一种是以数组的方式$M_product = M('Product');$map['pid'] = $proid;$p_result = $M_product->where($map)->select();