The thing I want to is like the job done in many news websites. Suppose I have a table of news. Each news have title and full text. So I want to show the news in a page. I want to limit the news displayed in a page to for example three news per page (using the limit
query which is easy) and I want to show only the titles. But I want the titles to be a link to the full text news. I mean when a user clicks on it, a new page shows up with the full text of that news. So what should I do?
news_titles.php:
<?php
//connection; then simple mysql_query and fetch (mysql is deprecated, so reconstruct it with another lib
$sql = "SELECT id, news_content, news_title FROM news;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<a href="news.php?id=<?=$row['id']; ?>"><?= $row['news_title']; ?></a>
<?php
}
?>
then create news.php:
<?php
//connection; then simple mysql_query and fetch (mysql is deprecated, so reconstruct it with another lib
$sql = "SELECT id, news_content, news_title FROM news WHERE id = ". $_GET['id'] . ";";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<p><?= $row['news_content']; ?>
<?php
}
?>
It will create you hyperlinks with news title's leading to news id and showing news_content in it. It will access news.php via i.e. news.php?id=5
If you get the idea, you may change some things for more security, clean and fresh code, and design
A page where you echo $row['title'] linked to $row['id'] and a page which recieves $_GET['id'] = $row['id'] so it echoes $row['new'] (SELECT
newfrom news WHERE id = $_GET['id'])