【发布时间】:2018-09-03 00:38:42
【问题描述】:
所以我有一个简单的问题,我坚持下去。我必须使用与提供的代码中相同的逻辑,但这次我必须创建一个新页面 - 比如说"article.php",然后我必须将"Delete" 按钮更改为"Show" 按钮。
这很容易,但我不能做以下事情:
当用户单击“显示”按钮时,链接必须将他重定向到“article.php”页面,然后显示所选列的所有值。
这将如何发生?再次使用"foreach" 循环还是?...
我真的不知道该怎么做。
任何帮助将不胜感激!
<?php
include "app".DIRECTORY_SEPARATOR."config.php";
include "app".DIRECTORY_SEPARATOR."db-connection.php";
$foo_connection = db_connect($host, $user_name, $user_password, $database);
$sql = "SELECT * FROM articles";
$result = mysqli_query($foo_connection, $sql);
if(mysqli_num_rows($result) > 0){
print "<table>
<tr>
<th>Article ID</th>
<th>Article heading</th>
<th>Article text</th>
<th>Article author</th>
<th>Article published</th>
<th>Article delete</th>
</tr>";
foreach($result as $key => $cols){
print "<tr>".
"<td>".$cols['id']."</td>".
"<td>".$cols['heading']."</td>".
"<td>".$cols['text']."</td>".
"<td>".$cols['author']."</td>".
"<td>".$cols['published']."</td>".
"<td><a href='app/sql/delete.php?id=".$cols['id']."'>Delete</a></td>".
"</tr>";
}
print "</table>";
}
else {
print "0 results";
}
mysqli_close($foo_connection);
【问题讨论】:
-
使用
$_GET['']或使用会话 -
您好,Dean.. 请您说的更具体一点。 :)
-
好的,创建一个article.php,然后通过同一页面上的
$_GET['id']值显示该页面上的文章,因此url将是url/article.php?set=id,就像那样- -
好的,我会试试的,我的朋友。
-
这不是重复,我的朋友,我必须使用相同的逻辑:).. 不同,可能有点,但它不同。