-1
我想從我的數據庫location
中獲取我的位置city
和country
數據。加入兩張表以獲取數據
這是我的代碼:
$data = mysql_fetch_array(mysql_query("
SELECT
u.`prename`,
u.`surname`,
DATE_FORMAT(u.`birthday`, '%d. %M') AS bday,
l.`city`,
l.`country`
FROM
`users` AS u
LEFT JOIN `users_location` AS ul ON ul.`uid` = u.`id`
LEFT JOIN `locations` AS l ON l.`id` = ul.`location_id`
WHERE u.`id`='".(int) ($_GET['id'])."'"));
在users_location
指定哪些用戶具有location_id
。
(users_location
結構:id
,uid
,location_id
)
在locations
是city
和country
名稱。
但是使用我的查詢city
和country
是空的。我猜是因爲我的加入聲明?
該聲明對我來說是正確的。 – Lorenz
問題是什麼?是的,這就是「左連接」,但是你有問題嗎? –
請在使用前清理GET變量:/ – demonking