Yii苦手 2012-03-21 14:27:15 8610次浏览 5条回复 0 0 0

$gid = $this->gid;

if ($gid) {

   $model = Picgroup::model ()->findAllBySql ( 'select id from Picgroup where name like "%:name%"', array (':name' => $gid ) );
   $criteria->compare ( 'gid', $model->id );

}

我想通过页面传来的gid参数用模糊查询去表里查一个id 但是什么都查不到 我模糊查询的语法写的有错误吗?第一次用不太清楚 请指点下 谢谢! PS:我的数据库里 绝对有满足查询条件的值!

  • 回复于 2019-04-12 10:27 举报

    如果根据数据库字段名查询呢

  • 回复于 2012-03-23 10:39 举报

    自己解决了[code] $match = $this->gid;

    	if ($match) {
    		$match = addcslashes ( $gid, '%_' );
    		$model = Picgroup::model ()->find ( array( 
    			'select' => 'id',
    			'condition'=> 'name LIKE :match',
    			'params'=> array (':match' => "%$match%" ) 
    		));
    		$criteria->compare ( 'gid', $model->id, true );
    	}[/code]语法写的有错误!
    
  • 回复于 2012-03-22 12:45 举报

    $criteria->compare ( 'gid', $model->id,true);

  • 回复于 2012-03-21 18:46 举报

    返回空 什么也没查到 没报任何错误

  • 回复于 2012-03-21 14:55 举报

    有错误提示吗?还是返回为空?请加官方的QQ群,这样能看的问题并帮你解答的人会多一些!

您需要登录后才可以回复。登录 | 立即注册