To pass a parameter to output from the database[PHP,SQL]?

Hello there!
Learn PHP and write a small project more for of purchase practices.
The question how to show the page output, only the desired record with a unique identifier?
The table schema pages:
id, name, content, author, date

Table id each time new and unique.
The main page to display all records:
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>";
}

...

?>


My goal:
To make a page that displays some news, such as a unique ID, getting from the table
did this code:
code.php

}
$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"]);
}


It is a little changes to the code in the output of news, added to aydishnik were taken from a GET parameter....
Only in the end have handles to specify the option - code.php?id=1, code.php?id=2, etc...

Want to from the home page, I clicked "record," which passed this unique aydishnik for subsequent output
April 4th 20 at 13:53
2 answers
April 4th 20 at 13:55
Solution
echo '<td><a href="code.php?id=' . $result_row["id"] . '">Edit</a></td>';

only for God's sake get all these weird <table>

And in the receiving script
$sth = $dbh->prepare("SELECT content FROM `pages` where id = ?");
$sth->execute([$_GET["id"]]);
$result_row = $sth->fetch();
echo htmlspecialchars($result_row["content"]);

because the whole point of incomprehensible spells prepare / ekzekuto that prepare prepares the query with markers, and do variables passed to execute().
Hi!

Tried to poke in different ways, most likely lacking my experience, the id parameter is not passed, when pointing at the station when on the page that "ahref" is the empty code value.php?id=

Show the code of the main page
index.php
<?php

try{
 $dbh = new PDO('mysql:dbname=blog;host=localhost', 'root', ");
} catch (PDOException $e) {
die($e->getMessage());

}

 $sth = $dbh->prepare("SELECT * FROM `pages` ORDER BY `name`");
$sth->execute();
 $array = $sth->fetchAll();


foreach ($array as $result_row) {
 echo ($result_row["name"]);
 echo ($result_row["id"]);
 echo ($result_row["author"]);
 echo ($result_row["date"]);
 echo '<td><a href="code.php?id="' . $result_row['id'] . '">Edit</a></td>';

}



?>


Host script code.php
<?php
try{
$dbh = new PDO('mysql:dbname=blog;host=localhost', 'root', ");
} catch (PDOException $e) {
die($e->getMessage());

}
//$idka = $_GET["id"];
$sth = $dbh->prepare("SELECT content FROM `pages` where id = ?");
$sth->execute([$_GET["id"]]);
$result_row = $sth->fetch();
echo htmlspecialchars($result_row["content"]);


?>
- nona.OReilly commented on April 4th 20 at 13:58
echo '<a href="code.php?id='.$result_row['id'].'">Delete</a>';
- nona.OReilly commented on April 4th 20 at 14:01
April 4th 20 at 13:57
in principle, my bro Vanatrip made the rules codec, removed the extra two quotes and worked

echo 'Remove';

Thanks bro!all hugs
echo '<a href="code.php?id='.$result_row['id'].'">Delete</a>';
- nona.OReilly commented on April 4th 20 at 14:00

Find more questions by tags PHPSQL