下面的代碼應該顯示從我的表中隨機發布;它是這樣做的,但是它顯示的帖子與網址中的ID不同。隨機帖子的動態鏈接不符合帖子ID
如何讓它顯示URL中的內容?謝謝。
$db = new PDO('mysql:host=localhost;dbname=db;charset=utf8', 'user', 'pass');
$sql = $db->query('SELECT id FROM posts ORDER BY RAND() LIMIT 1');
$row = $sql->fetch(PDO::FETCH_ASSOC);
echo "<a href='random?page=".$row['id']."'>Randomize!</a><br>";
請找到「random.php頁面的相關部分如下:
$db = new PDO('mysql:host=localhost;dbname=db;charset=utf8', 'user', 'pass');
$sql = $db->query('SELECT * from posts ORDER BY RAND() LIMIT 1');
$row = $sql->fetch(PDO::FETCH_ASSOC);
echo "<a href = 'random.php?page=".$row['id']."'>Re - Randomize!</a><br>";
if ($row['sort'] == "image"){
echo "<b>Update: </b>", $row['tag'], "<br>";
echo "<img src='resize.php?w=240&img=./uploads/".$row['message']."'><br>";
echo "<b>", "By: ", "</b>", ($row['username']), "<br>";
echo "<b>", "At: ", "</b>", ($row['timestamp']), "<br>";
if($row['locked'] !='locked'){
echo "<a href ='edit.php?pid=".$row['id']."&login=true&edit=true' method='post' id ='form-id' data-ajax='false' '><b><span class = 'small_blue'>EDIT</span></b></a>";}
echo " ", " ";
echo "<span class = 'small_green'>", ($row['edited']), "</span>", " ", " ", ($row['locked']);
echo " ", " ";
}
else if ($row['sort'] == "audio"){
echo "<b>Update: </b>", $row['tag'], "<br>";
echo "<audio controls>";
echo "<source src='./uploads/".$row['message']."'>";
echo "</audio>", "<br>";
echo "<b>", "By: ", "</b>", ($row['username']), "<br>";
echo "<b>", "At: ", "</b>", ($row['timestamp']), "<br>";
if($row['locked'] !='locked'){
echo "<a href ='edit.php?pid=".$row['id']."&login=true&edit=true' method='post' id ='form-id' data-ajax='false' '><b><span class = 'small_blue'>EDIT</span></b></a>";}
echo " ", " ";
echo "<span class = 'small_green'>", ($row['edited']), "</span>", " ", " ", ($row['locked']);
}
else if ($row['sort'] == "video"){
echo "<b>Update: </b>", $row['tag'], "<br>";
echo "<video controls>";
echo "<source src='./uploads/".$row['message']."'>";
echo "</video>", "<br>";
echo "<b>", "By: ", "</b>", ($row['username']), "<br>";
echo "<b>", "At: ", "</b>", ($row['timestamp']), "<br>";
if($row['locked'] !='locked'){
echo "<a href ='edit.php?pid=".$row['id']."&login=true&edit=true' method='post' id ='form-id' data-ajax='false' '><b><span class = 'small_blue'>EDIT</span></b></a>";}
echo " ", " ";
echo "<span class = 'small_green'>", ($row['edited']), "</span>", " ", " ", ($row['locked']);
}
else {
echo "<b>Update:</b><br>";
echo ($row['message']), "<br>";
echo "<b>", "By: ", "</b>", ($row['username']), "<br>";
echo "<b>", "At: ", "</b>", ($row['timestamp']), "<br>";
if($row['locked'] !='locked'){
echo "<a href ='edit.php?pid=".$row['id']."&login=true&edit=true' method='post' id ='form-id' data-ajax='false' '><b><span class = 'small_blue'>EDIT</span></b></a>";}
echo " ", " ";
echo "<span class = 'small_green'>", ($row['edited']), "</span>", " ", " ", ($row['locked']);
}
你的代碼從頁面'random'使用'$ _GET ['page']'/'$ row ['id']'value? – Sean
@Sean抱歉,我的時間即將到期。將很快發佈。謝謝。 – adeoba
@Sean,我發佈了'random.php'頁面。謝謝。 – adeoba