Answer the question
In order to leave comments, you need to log in
Pass parameter for output from database[PHP,SQL]?
Hello!
I'm learning php and writing a small project, more for gaining practice.
The question is, how to display on the output page, only the desired record with a unique identifier?
Pages table schema:
id, name, content, author, date
Tables with id are new and unique every time.
Main page for displaying all entries:
index.php
....
$sth = $dbh->prepare("SELECT * FROM `pages` ORDER BY `name`");
$sth->execute();
$array = $sth->fetchAll();
foreach ($array as $result_row) {
echo "<tr>";
echo "<table><tr><td>" . $result_row["name"] . "<tr></td></tr>";
echo "<td>" . $result_row["id"] . "</td>";
echo "<td>" . $result_row["author"] . "</td>";
echo "<td>" . $result_row["date"] . "</td></table>";
echo "</tr>";
}
...
?>
}
$idka = $_GET["id"];
$sth = $dbh->prepare("SELECT content FROM `pages` where id = '$idka'");
$sth->execute();
$array = $sth->fetchAll();
foreach ($array as $result_row) {
echo htmlspecialchars($result_row["content"]);
}
Answer the question
In order to leave comments, you need to log in
echo '<td><a href="code.php?id=' . $result_row["id"] . '">Edit</a></td>';
<table>
$sth = $dbh->prepare("SELECT content FROM `pages` where id = ?");
$sth->execute([$_GET["id"]]);
$result_row = $sth->fetch();
echo htmlspecialchars($result_row["content"]);
in principle, my bro FanatPHP made the norm codec, removed the extra two quotes and earned
echo ' Delete ';
Thanks bro! hugged everyone
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question