砂舞夕暮 2015-01-08 16:59 采纳率: 0%
浏览 1648

php加一句如果在数据库里没某条记录,则显示提示消息。判断语句应该怎么改?求大神抱大腿!

function xuesheng(){
$c=M('case')->field('id')->where("upid=5 and state=1")->findAll();
foreach($c as $k => $v){
$caseid[]=$v['id'];
}
$wherecase=" and cid in (".implode(',',$caseid).")";
$qu=M('news')->field('pic1')->where('state=1'.$wherecase)->group('pic1')->order('order asc ,id desc')->findAll();
$this->assign('qu',$qu);
if($_POST){
$list=M('news')->where("state=1 and pic1='$_POST[pic1]' and pic='$_POST[pic]' and title='$_POST[title]'".$wherecase)->order('order asc ,id desc')->findAll();
if($list){
foreach($list as $k => &$v){
$case=M('case')->field('name')->where("id=$v[cid]")->find();
$v['case_name']=$case['name'];
}
}
$this->assign('list',$list);
}
$this->display('xuesheng');
}
如何加一句,如果没有找到相关信息,就提示 对不起,您没有被录取。

  • 写回答

5条回答 默认 最新

  • 傲雪星枫 2015-01-09 02:12
    关注

    function xuesheng(){
    $c=M('case')->field('id')->where("upid=5 and state=1")->findAll();
    foreach($c as $k => $v){
    $caseid[]=$v['id'];
    }
    $wherecase=" and cid in (".implode(',',$caseid).")";
    $qu=M('news')->field('pic1')->where('state=1'.$wherecase)->group('pic1')->order('order asc ,id desc')->findAll();
    $this->assign('qu',$qu);
    if($_POST){
    $list=M('news')->where("state=1 and pic1='$_POST[pic1]' and pic='$_POST[pic]' and title='$_POST[title]'".$wherecase)->order('order asc ,id desc')->findAll();
    if($list){
    foreach($list as $k => &$v){
    $case=M('case')->field('name')->where("id=$v[cid]")->find();
    $v['case_name']=$case['name'];
    }
    }else{
    $this->assign('message', '对不起,您没有被录取。');
    }
    $this->assign('list',$list);
    }
    $this->display('xuesheng');
    }

    然後模板那裏要判斷

    {if $message!=''}
    {$message}
    {else}
    這裏寫之前list的代碼
    {/if}

    评论

报告相同问题?

悬赏问题

  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp