你好我相當新的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