php mysql if else更新数据库并显示基于数据库的不同链接

时间:2017-03-03 16:07:46

标签: php mysql if-statement

我正在学习php,我正在尝试添加一些修改项目状态的按钮。我设法让我的代码执行此操作并且它正在工作,但我确信它可以更好地编写,我想知道是否可以在不刷新页面的情况下完成此操作?任何想法将不胜感激。 感谢。

if (isset($_GET['status'])) {
$id = (int)$_GET['id'];
$status = (int)$_GET['status'];
$statusSql = "UPDATE projects SET status = '$status' WHERE id ='$id'";
$db->query($statusSql);
header('Location: projects.php');
}
........
<?php
      if(($project['status']) == 0 ) {
         echo "<a href='projects.php?status=1&id={$project['id']}' class='btn btn-xs btn-default'>
           <span class='glyphicon glyphicon-play'></span>
           </a>&nbsp New Project";
      }elseif(($project['status']) == 1 ){
         echo "<a href='projects.php?status=2&id={$project['id']}' class='btn btn-xs btn-default'>
          <span class='glyphicon glyphicon-pause'></span>
          </a>&nbsp In Progress &nbsp<a href='projects.php?status=3&id={$project['id']}' class='btn btn-xs btn-default'>
           <span class='glyphicon glyphicon-stop'></span>
           </a>";
      }elseif(($project['status']) == 2 ){
        echo "<a href='projects.php?status=1&id={$project['id']}' class='btn btn-xs btn-default'>
         <span class='glyphicon glyphicon-play'></span>
         </a>&nbsp On Hold</span>
          </a>";
      }elseif(($project['status']) == 3 ){
        echo "<a href='projects.php?status=1&id={$project['id']}' class='btn btn-xs btn-default'>
         <span class='glyphicon glyphicon-play'></span>
         </a>&nbsp Finished</span>
          </a>";
      };

&GT;

0 个答案:

没有答案