<?php
include("connect.php");
?>
<?php
echo "<h1>The Hashtag: </h1>";
if(isset($_GET['hashtag'])){
echo $_GET['hashtag'];
}
// Select the ID of the given hashtag from the "hashtags" table.
$tqs = "SELECT `id` FROM `hashtags` WHERE `hashtag` = '" . $_GET['hashtag'] . "'";
$tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc));
$row = mysqli_fetch_assoc($tqr);
// This prints e.g.:
// 100
echo "<br/><br/>";
print_r($row['id']);
// Select the threads from the "thread" table which contains the hashtag ID number.
$tqs_two = "SELECT * FROM `thread` WHERE `hashtag_id` IN ('" . $row['id'] . "')";
$tqr_two = mysqli_query($dbc, $tqs_two) or die(mysqli_error($dbc));
$row_two = mysqli_fetch_assoc($tqr_two);
echo "<br/><br/>";
print_r($row_two);
?>
腳本應該由主題標籤的ID碼選擇行。它應該在表的「hashtag_id」列中查看是否可以在那裏找到該ID號,如果可以在那裏找到它,那麼它應該選擇該行。
身份證號碼位於由逗號分隔的「hashtag_id」列內。
例子:
98, 99, 100
基本上,有沒有辦法做一個SQL查詢,看看是否列「包含」該ID號或可能有別的東西在這裏?
任何建議表示讚賞。
'$ TQS = 「SELECT ID FROM主題標籤#標籤WHERE =「」。 $ _GET ['hashtag']。 「'」;'不應該'hashtag'是'hashtag_id'? – 2014-10-17 16:38:26
無關:$ tqs易受SQL注入影響。 – 2014-10-17 16:45:18
它是來自GET方法的hashtag的「名稱」。 – ftxn 2014-10-17 17:07:12