我是yii中的新手。我正在尝试从数据库中选择数据并列出它。我有控制器名称sitecontroller.php和查看页面search_result.php。我可以选择并列出没有条件的数据,但我想选择数据有条件
Controller - Sitecontroller.php
<?php
class SiteController extends Controller
{
public function actionsearch_result()
{
$title=$_GET['title'];
$experience=$_GET['experience'];
$criteria=new CDbCriteria();
$Criteria->condition = "title like '%$title%' or key_skills like '%$title%'";
$count=Job::model()->count($criteria);
$pages=new CPagination($count);
$pages->pageSize=2;
$pages->applyLimit($criteria);
$model=Job::model()->findAll($criteria);
$this->render('search_result',array('model' =>$model,'pages' => $pages));
}
}
&GT;
我的观点文件 - search_result.php
<div style="float:right;margin-right:285px;">
<h1>Search Results</h1>
<ul style="list-style:none; ">
<?php
foreach($model as $models)
{
$job_id=$models->id;
?>
<li><p><?php echo $models->title; ?></p>
<p><?php echo $models->company_name ; ?></p>
<p><?php echo $models->description ; ?></p>
<p>Keyskill:<?php echo $models->key_skills ; ?><p>
</li>
<?php
}
?>
</ul>
<p><?php $this->widget('CLinkPager', array(
'pages' => $pages,
)) ?></p>
</div>
有人帮帮我吗?
答案 0 :(得分:0)
用我的代码替换您的代码 -
$Criteria->condition = "title like '%$title%' or key_skills like '%$title%'";
$criteria->condition = "title like '%$title%' or key_skills like '%$title%'";
取代&#34; C&#34;使用&#34; c&#34;。