PHP隐藏mysql的内容


PHP hiding content from mysql

嗨,我对php和mysql相当陌生,所以希望有人能给我指出正确的方向。

我有一个包含以下列的表。

+----+---------------------+---------------+------+
| id | date                | news_content  | shows|
+----+---------------------+---------------+------+
|  1 | 2013-03-19 14:47:27 | This is news1 |  1   |
|  2 | 2013-03-19 14:47:27 | This is news2 |  1   |
|  3 | 2013-03-19 14:47:37 | This is news3 |  1   |
|  4 | 2013-03-19 14:47:37 | This is news4 |  1   |
+----+---------------------+---------------+------+

Show可以为0或1(默认值)。如果值为0,我想隐藏news_content和日期。

printnews功能打印出所有的新闻文章和3个锚链接显示或隐藏,编辑和添加。我必须改变一些东西在我的mysql数据库,使它不显示新闻时显示=0?或者用php有其他方法吗?

编辑:当我按下隐藏链接时,我想将显示值设置为0并隐藏该文章,当我按下显示链接时,我想显示文章。目前我没有任何东西,使文章隐藏时,它的值为0。

function printnews() {
    $data = mysql_query("SELECT * FROM news ")  
    or die(mysql_error());  
    while ($info = mysql_fetch_array($data)) {
         $id = $info['id']; 
         $show = $info['shows'];
         if($show == 1) {
           echo "<br><a href=show.php?id=$id&shows=0> Show </a><br>";
         }   
         else if($show == 0) {
           echo "<br><a href=show.php?id=$id&shows=1> Hide </a><br>";
         }
         // Print Articles and Date
         echo "<br><a href=Edit.php?id=$id>Edit</a><a href='addnews.php'> Add </a><br><strong>". $info['date']."</strong><br>". $info['news_content'] . "<hr><br>";
    }

我知道我不应该使用mysql扩展名,所以请忽略任何有关的评论

您可以更新您的SELECT查询,只获取show设置为1的数据。

SELECT * 
FROM `news`
WHERE `shows` = 1