php如何判断数据库字段内容
阿神
阿神 2017-04-11 09:19:43
0
2
647

这个是模块代码

        if($article_info['grouptime']){
    $otherTitle = $this->model('publish')->getall("article","grouptime='".$article_info['grouptime']."' AND grouptime!=''");
}else{
    $otherTitle =  array();
}

我想通过php中的if语句来判断,当当前文章的grouptime这个字段值的相同数据大于1时就显示
这个代码

<p class="detail-mod J_floor">
          <p class="mod-title sp"><span></span>相关百科</p><ul class="extend-ctn">
                    <?php foreach ($this->otherTitle as $key => $v): ?>
                    
                <?php if($_GET['id']!=$v['id']){ ?>
                 <li><a href="/article/<?php echo $v['id']; ?>" title="<?php echo $v['title']; ?>"><?php echo $v['xtitle']; ?></a></li>
                <?php } ?><?php endforeach ?></ul>
            
        </p>

,否则就显示【没有百科】,要怎么写if 跟 else呢?

阿神
阿神

闭关修行中......

Antworte allen(2)
左手右手慢动作
select * from table group by grouptime having count(grouptime) > 1

这样可以查出数据库中grouptime重复数大于1的数据

php代码

$muysqli = new mysqli($host,$user,$pwd,$dbname);
$sql = "select * from table group by grouptime having count(grouptime) > 1";
$res = $mysqli->query($sql);
if(count($res) > 1){//grouptime数量大于1
    //do something
}else{//grouptime不大于1
    //do something
}

==============================================================

在第二段代码前面加上if判断

<?php
if(count($this->otherTitle) > 1){
?>
<p class="detail-mod J_floor">
    <p class="mod-title sp"><span></span>相关百科</p>
        <ul class="extend-ctn">
            <?php foreach ($this->otherTitle as $key => $v): ?>
            <?php if($_GET['id']!=$v['id']){ ?>
             <li><a href="/article/<?php echo $v['id']; ?>" title="<?php echo $v['title']; ?>"><?php echo $v['xtitle']; ?></a></li>
            <?php }
             endforeach 
             ?>
     </ul>
</p>
<?php  
}else{
    echo "【没有百科】";
}
?>
Ty80
$res = $db->query("select count(id) sum,grouptime from table group by grouptime having sum > 1");
if($res){

} else {
 
}
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage