我想在不同的表格中显示数据库中的数据,但场地和位置无法正确显示。 这是我的代码
<?php
include "database_conn.php";
if(isset($_GET['eventID'])){
$id = $_GET["eventID"]; //get event id
}
else {
header ("Refresh : 5; url=chooseEventList.php");//redirect to choose title
die ("Please use the Choose Event Title List");
}
//get event id
$id = $_GET["eventID"];
//select event
$sqlEvent = "SELECT * FROM te_events , te_venue , te_category
WHERE eventID =".$id
;
//excute sql statemente
$event = mysqli_query($conn , $sqlEvent) or die (mysqli_error($conn));
$row = mysqli_fetch_assoc($event) or die (mysqli_error($conn));
//extract each field$
$id = $row ["eventID"];
$title = $row ["eventTitle"];
$desc = $row ["eventDescription"];
$venueId = $row ["venueID"];
$venue = $row ["venueName"];
$location = $row ["location"];
$categoryId = $row ["catID"];
$eStart = $row ["eventStartDate"];
$eEnd = $row ["eventEndDate"];
$ePrice = $row ["eventPrice"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title> event details</title>
<meta charset = "utf-8">
</head>
<body>
<fieldset>
<legend>Event details</legend>
<div>
Event title
<input type ="text" name ="eventTitle" value="<?=$title?>"readonly/>
</div>
<div>
Description
<textarea style="resize:none" name="desc" rows="10" cols="40"><?=$desc?></textarea>
</div>
<div>
Venue Name
<input type = "text" name="venueName" value="<?=$venue?>"readonly/>
</div>
<div>
Location
<input type="text" name="location" value="<?=$location?>"readonly/>
</div>
<div>
Event Start Date
<input type="text" name="eventStartDate" value="<?=$eStart?>"readonly/>
</div>
<div>
Event End Date
<input type="text" name="eventEndDate" value="<?=$eEnd?>"readonly/>
</div>
<div>
Event Price
<input type="text" name="eventPrice" value="<?=$ePrice?>"readonly/>
</div>
</fieldset>
</body>
</html>
我认为我的问题存在于$ sqlEvent中。
当我删除'WHERE eventID = " .$id;'
时,当我点击上一页中的事件标题时,它会显示相同的详细信息。
告诉我是否需要上一页。
答案 0 :(得分:2)
你的sql错了你应该使用join
SELECT * FROM te_events
INNER JOIN te_venue ON te_events.tvId = te_venue.tvId
INNER JOIN te_category ON te_events.tcId = te_category.tcId
WHERE te_events.eventID =".$id