dqq9695 2017-04-20 08:14
浏览 117

如何通过检查枚举来显示数据库中的数据

so my table is like this....

comments   |   status
 asd       |     1
 qwe       |     0
 nmb       |     1
 qwer      |     0

so i have here my query update which i use an enum.. if status is 1 the result wont be displayed but if status is 0 it will be displayed..

function updatestatuspost($poid,$uid)
{
    $sql = "UPDATE post SET status = '1' WHERE post_id='$poid' AND member_id = '$uid'";
    $query = $this->dbh->prepare($sql);
    $result = ($query->execute() ? true : false);
    return $result;
}

this query is for display all the data on my database which limits to 5

function getAllPost(){
 $query = "SELECT * FROM post JOIN members ON members.member_id=post.member_id ORDER BY post_id DESC LIMIT 5";
 $result = $this->dbh->prepare($query);
 $result->execute();
 $data = array();
 while($row = $result->fetch(PDO::FETCH_ASSOC)){
 $data[] = $row;
}
return $data;
}

this query is fine but the problem is the displaying part..

<?php
$res=$db->getAllPost();

    foreach ($res as $value)
    {
        if('1' == $value['status'] )
        {
?>
<?php
} else{
?>
   <strong class="font-1-2" style="margin-left:15px;"><?php echo '<a class="text-muted" href="profileview?member_id='.$value['member_id'].'">'.$value['firstname'].' '.$value['lastname'].'</a>';?></strong> 
   }
}

what happens is when the if is == 1 all of my data is not being displayed but when if is != 1 all data is being displayed even if other data is = 0.. is there any way to call the value from my db which is 1/0 and compare it using if statement. cause what i wanted to do is when status is if the data has status of 1 it will not be displayed and will be displayed and if is 0..

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算