如何根据php条件显示隐藏的html表格行 [英] how to show hide html table row based on php condition

查看:55
本文介绍了如何根据php条件显示隐藏的html表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据 mysql 使用 php 获取的列的状态值显示/隐藏表行.

I want to show/hide table row based on status values of the fetched columns for mysql using php.

工作代码:此部分工作正常

while($row = mysql_fetch_array($sql))  
{
$name[] = $row['name'];
$title[] = $row['title'];
$prize[] = $row['prize'];
$status[] = $row['status'];  // this  will save values as enabled or disabled
$points[] = $row['points'];

}


<?php 

      while($row = mysql_fetch_array($sql))  

{

     echo "<tr> ";
     echo "<td>" .$row[name] . "</td>";
    echo "<td>" .$row[points] . "</td>";
        }
     echo "</tr> " ;
?>

问题:我需要解决这个问题

我无法显示上面给出的表格,因为更多的值将从其他表格中获取,以显示到表格行中.我正在显示这样的表格.

I cant display the table as given above due to some more values, that will be taken from other tables, to be shown into the table rows. I am displaying the tables like this.

<tr ><td><?php echo "$title[0]";?></td><td>complete <?php echo "$task[0]";?> </td><td></td></tr>
<tr ><td><?php echo "$title[1]";?></td><td>complete <?php echo "$task[1]";?> </td><td></td></tr>

问题:

请指导我如何隐藏或显示问题中定义的行部分,使用

Kindly guide me how I hide or show the rows , as defined in problem section , using the value of

$status[] = $row['status'];

$status[] = $row['status'];

,将启用或禁用

推荐答案

喜欢这个

 while($row = mysql_fetch_array($sql))  
{
   if($row['status']=="enabled")
  {
   echo "<tr> ";
   echo "<td>" .$row[name] . "</td>";
   echo "<td>" .$row[points] . "</td>";
   echo "</tr> " ;
  }
}

对于其他行,您可以这样做

For the other lines you can do like this

<?php if($status[0] == "enabled") { ?>
    <tr ><td><?php echo "$title[0]";?></td><td>complete <?php echo "$task[0]";?> </td><td></td></tr>
<?php } ?>

编辑

如果所有数组的大小相同,您可以尝试这样的操作

For loop if all your arrays have the same size, you can try something like this

<?php for($i=0;$i<sizeof($title);$i++) {
if($status[$i]=="enabled"){
?>
<tr ><td><?php echo $title[$i];?></td><td>complete <?php echo $task[$i];?> </td><td></td></tr>
<?php  }
} ?>

这篇关于如何根据php条件显示隐藏的html表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆