我正在創(chuàng)建一個新聞網(wǎng)站,當(dāng)我創(chuàng)建一篇新文章時,標(biāo)題/文本會在數(shù)據(jù)庫中注冊。文章位于帶有頁眉/頁腳的動態(tài) PHP 頁面中,文本本身是從數(shù)據(jù)庫中調(diào)用的。在索引上有一個包含指向每篇文章的鏈接的列表,我希望這些鏈接能夠自動更改 ID。索引.php<?php include "header.php"; session_start();?><?php include "slideshow.php"; ?><?php include "db.php"; ?> <br> <table class="table_index"> <?php while ($line = mysqli_fetch_array($query)) { echo '<tr><td class="td_tit"><a href="example_article.php" >'.$line["title_article"].'</a></td></tr>'; echo '<tr><td class="td_subt"><a href="example_article.php" >'.$line["subtitle_article"].'</a></td></tr>'; $_SESSION['id_article'] = $line["id_tb_article"]; } ?> </table><?php include "footer.php"; ?> example_article.php<?php session_start(); include "header.php"; $id_article = $_SESSION['id_article']; $query = "SELECT title_article, subtitle_article, content_article FROM tb_article WHERE id_tb_article = $id_article"; $conn = mysqli_connect('127.0.0.1:3307', 'root', '', 'article') or die("error"); $result = mysqli_query($conn, $query); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "<div class='titlediv'><h1 class='title'>" . $row["title_article"]. "</h1></div><div class='titlediv'><h3 class='title'>". $row["subtitle_article"]. "</h3></div><div class='textdiv'><p class='text'>" . $row["content_article"]. "</p></div><br>"; } } else { echo "0 results"; } include "footer.php";?>
如何通過 PHP 自動更改 SQL 查詢的 ID?
阿波羅的戰(zhàn)車
2021-11-26 15:19:46