-1
在我的用戶配置文件:加入
我想和標誌性建築是用戶喜歡的列表,它已在最喜歡的表被添加,我的查詢中我加入收藏夾和標誌性表,但什麼都沒有檢索?
// PHP
<?php
include "config.php";
header('Content-Type: application/json');
$userid = array_key_exists('userid', $_GET) ? $_GET['userid'] : null;
$landmarkid = array_key_exists('landmarkid', $_GET) ? $_GET['landmarkid'] : null;
$data=array();
$q = mysqli_query($con,"SELECT c.userid,c.L_ID,u.Title,u.Image,u.L_ID FROM favorite c inner join landmarks u
on u.L_ID=c.L_ID WHERE ".(isset($userid) ? "c.userid=$userid" : (isset($landmarkid) ? "c.L_ID=$landmarkid" : ""))." ORDER BY c.L_ID");
if($q){
$num_rows = mysqli_num_rows($q);
if($num_rows > 0){
while ($row=mysqli_fetch_object($q)){
$data[]=$row;
}
}
echo '{"favourites":'. json_encode($data) .'}';
}
?>
//Tables
CREATE TABLE `favourite` (
`userid` int(11) NOT NULL,
`L_ID` int(11) NOT NULL
)
CREATE TABLE `landmarks` (
`L_ID` int(11) NOT NULL,
`Image` text NOT NULL,
`Title` text NOT NULL,
)
CREATE TABLE `users` (
`userid` int(11) NOT NULL,
)
歡迎來到Stack Overflow。我們是志願者。閱讀大量代碼需要時間。不幸的是,您的問題包含大量不相關的代碼,但不包含來自表格的樣本數據或您想要的結果樣本。請[編輯]問題以顯示一些樣品。 –
你到底想要什麼?加入2表成一個? – NoOorZ24
我已編輯問題 –