gpt4 book ai didi

mysql - 使用变量选择列

转载 作者:行者123 更新时间:2023-11-29 00:25:50 26 4
gpt4 key购买 nike

可能不是对标题的最佳描述,但我真的想不出任何东西。我想要发生的是,我可以创建一个查询,该查询使用 userID 作为关系从列表中选择类型,然后选择城镇。

TABLE listings
saleID userID type description
1 23 clothing nice clothing
2 45 clothing More nice Clothing

TABLE users
userID country county town
23 uk county townname1
24 uk county townname2

变量在 url 中设置为 get eg) ?type=clothing&town=townname2

if (!isset($type)){
$query = "SELECT * FROM listings";
}
if (isset($type)) {
$query = "SELECT * FROM listings WHERE type = '{$type}'";
}

这是我坚持的一点 我想获得所有带有变量 $type 'clothing' 的列表,然后从具有变量 $town 的城镇的用户中选择

if (isset($town)) {
$query = "SELECT users.town listings.userID listings.type FROM listings
WHERE type = '{$type}'
INNER JOIN users
ON users.town = '{$town}'";
}

希望我已经解释得足够清楚了。请帮我解决最后一个问题

最佳答案

SELECT u.town l.userID, l.type 
FROM listings l
INNER JOIN users u on u.userID = l.userID
WHERE l.type = '{$type}'
AND u.town = '{$town}'

关于mysql - 使用变量选择列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18961398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com