php - 如果数据库表为空,阻止显示“删除”按钮?

标签 php mysql

如果 $count > 0,如何用该数组隐藏删除按钮。PHP 代码中有办法做到这一点吗?有人可以帮忙吗?我也欢迎任何想要修改代码以使其更安全的人。

<form action="checkbox.php" method="post">

<?php
$query = "SELECT filmTitle, filmRole, filmDirector, idfilm FROM filmInfo, actorsInfo
WHERE (actorsInfo.id = filmInfo.id_actor) AND email = '$_SESSION[email]'";

$result = mysql_query($query);
$count=mysql_numrows($result);

if($count > 0){
echo "<table>";

echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";   
echo "<tr style='font-weight: bold;'>";   
echo "
    <td width='20' align='center'>#</td>
    <td width='200' align='center'>TITLE</td>
    <td width='200' align='center'>ROLE</td>
    <td width='200' align='center'>DIRECTOR</td>"; 
echo "</tr>";

$row_number = 1;
while ($row = mysql_fetch_array($result)) {

  $id_actor= $row["id_actor"];
  $idfilm= $row["idfilm"]; 
  $filmTitle= $row["filmTitle"];
  $filmRole= $row["filmRole"];
  $filmDirector= $row["filmDirector"];


  echo"<tr>";
  echo '<td><input name="checkbox[]" value="'.$idfilm.'" type="checkbox" 
    id="checkbox'.$row_number.'" /></td>';


  for ($i=0; $i<3; $i++)  {
   echo"<td> $row[$i]</td>";
  }
  echo"</tr>";

  $row_number++;
  }
  echo"</table>";
  }

  ?>

  <input type="submit" name="deletefilm" value="Delete" />
  </form>

最佳答案

if($count > 0){

    echo "<table>";

    echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";   
    echo "<tr style='font-weight: bold;'>";   
    echo    "

    <td width='20' align='center'>#</td>

    <td width='200' align='center'>TITLE</td>
    <td width='200' align='center'>ROLE</td>
    <td width='200' align='center'>DIRECTOR</td>"; 
    echo "</tr>";

    $row_number = 1;
    while ($row = mysql_fetch_array($result)) {

    $id_actor= $row["id_actor"];
    $idfilm= $row["idfilm"]; 
    $filmTitle= $row["filmTitle"];
    $filmRole= $row["filmRole"];
    $filmDirector= $row["filmDirector"];


    echo"<tr>";
    echo '<td><input name="checkbox[]" value="'.$idfilm.'" type="checkbox" 
    id="checkbox'.$row_number.'" /></td>';


    for ($i=0; $i<3; $i++)  {
       echo"<td> $row[$i]</td>";
    }
    echo"</tr>";

    $row_number++;
    }
    echo"</table>";
}

关于php - 如果数据库表为空,阻止显示“删除”按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18907283/

相关文章:

php - 将 PHP 变量传递给 JavaScript getElementById

mysql - 字段列表中未知的列名 - MySQL

高事务表ID引用字段多的MySQL索引规划

mysql - 当执行多个唯一列时,我可以在 laravel 5.6 中给出自定义名称吗?

php - MySQL多表DELETE报错

php - 在 Laravel 中调用附加或分离时,如何让 `pivot table` 模型触发保存/保存的模型事件?

php - 基于Mysql数据预填充/预检查复选框

php - 如何将无限数据存储到mysql中的特定列

php - 如何在 php 中显示正在运行的 mysql 查询

mysql - 如果找到,SQL 将字段内容替换为另一个表中的内容