你好我相当新的PHP和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 |
+----+---------------------+---------------+------+
显示的值可以是0或1(默认值)。如果值为0,我想隐藏news_content和日期。
该printnews函数打印出所有的新闻和3个链接显示或隐藏,编辑和添加。 我是否必须在我的mysql数据库中更改某些内容,以便它在show = 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扩展,所以请忽略有关的任何意见。
是你有没有工作? – 2013-03-21 23:24:03
@Explosion Pills在home.php中调用该函数,此时show.php为空。所以没有它不起作用 – Ben 2013-03-21 23:25:58