我创建了一个JOIN来显示所需的数据,以允许用户查看可供他们选择的所有故事。
$sql = ("
SELECT *
FROM guest
, story
WHERE guest.userid = story.userid
AND guest.userid = $_SESSION[id]
ORDER
BY story.st_name
");
$result = mysqli_query($db, $sql);
echo "<table class='p'>";
echo "<tr>";
echo "<td class='z'>Story Name</td>";
echo "<td class='z'>Email</td>";
echo "</tr>";
while($row = mysqli_fetch_array($result)) {
$st_name = $row['st_name'];
$email = $row['email'];
$st_id = $row['st_id'];
$g_id = $row['g_id'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
echo "<tr>";
echo "<td class='b'>".$st_name."</td>";
echo "<td><input type='checkbox' name='checkbox[]' class='checkboxes' value='$row[st_id],$row[g_id],$row[first_name],$row[last_name],$row[st_name]' >".$email."</td>";
echo "</tr>";
}
然后可以将这些数据保存到数据库表中。所有这些都很好。但是,当他们再次调用该页面时,将再次显示相同的数据,如果他们选择相同的数据,则会在表中重复该数据。
此语句显示表中已保存的数据。
$sql = ("SELECT * FROM gs WHERE id = $_SESSION[id] ");
$result = mysqli_query($db, $sql);
while($row = mysqli_fetch_array($result)) {
$firstname = $row['first_name'];
$lastname = $row['last_name'];
$storyname = $row['story_name'];
$stid = $row['st_id'];
$storyname = $row['story_name'];
我想如何在原始的SELECT语句中创建一种方法来测试并查看此数据是否存在,然后不显示它。但是我无法弄清楚这种说法。