So I have a simple question and I'm stuck with it. I have to use the same logic like in the provided code, but this time I have to make a new page - let's say "article.php"
, then I have to change the "Delete"
button with "Show"
button.
This is easy, but I can't do the following thing:
When a user clicks on the "SHOW" button, the link must redirect him into the "article.php" page, and after that to display ALL of the VALUES for the selected COLUMN.
How is this going to happen? Using "foreach"
cycle again or?...
I really don't know how to do it.
Any help will be highly appreciated!
<?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);