[英]MySQL query not showing with LEFT JOIN and multiple AND clauses
I added the line AND t.cover='$c'
and now it will not show any results. 我添加了行AND
t.cover='$c'
,现在它不会显示任何结果。 However, all variables are correct. 但是,所有变量都是正确的。 If I run the line in phpMyAdmin it will display the results fine.
如果我在phpMyAdmin中运行该行,它将很好地显示结果。 Am I missing syntax in PHP?
我是否缺少PHP中的语法? If I remove the
t.cover='$c'
the script works fine on the web. 如果删除
t.cover='$c'
则脚本可以在网络上正常运行。 $c
is simply a $_GET['c']
that will either be empty or will equal 0, which I redefine to 'No'. $c
只是$_GET['c']
,将为空或等于0,我将其重新定义为“ No”。
if($t != '') {
if($c == 'No') {
$getListings = mysql_query("SELECT * FROM events t LEFT JOIN bars b on t.venue=b.name WHERE t.date='$date' AND t.type='$t' AND t.cover='$c' AND b.active='1' ORDER BY t.promoted DESC, t.order ASC");
} else {
$getListings = mysql_query("SELECT * FROM events t LEFT JOIN bars b on t.venue=b.name WHERE t.date='$date' AND t.type='$t' AND b.active='1' ORDER BY t.promoted DESC, t.order ASC");
}
} else {
if($c == 'No') {
$getListings = mysql_query("SELECT * FROM events t LEFT JOIN bars b on t.venue=b.name WHERE t.date='$date' AND t.cover='$c' AND t.type='$t' AND b.active='1' ORDER BY t.promoted DESC, t.order ASC");
} else {
$getListings = mysql_query("SELECT * FROM events t LEFT JOIN bars b on t.venue=b.name WHERE t.date='$date' AND b.active='1' ORDER BY t.promoted DESC, t.order ASC");
}
}
My biggest confusion is why it works in phpMyAdmin but yet displays no rows on the web. 我最大的困惑是为什么它可以在phpMyAdmin中工作,但在网络上却不显示任何行。
It seems I have tried everything on Google and still no luck. 看来我已经尝试了Google上的所有功能,但仍然没有运气。 I wish it would throw an error or something to point me in a direction, but it just comes up as though the query was empty.
我希望它会引发错误或使我指向某个方向,但是它只是好像查询为空而出现。 If anyone has any idea, I am still looking for input.
如果有人有任何想法,我仍在寻找输入。 Maybe LEFT JOIN is doing it?
也许LEFT JOIN正在这样做吗?
... LEFT JOIN bars b on t.venue=b.name AND b.active=1
... ...
LEFT JOIN bars b on t.venue=b.name AND b.active=1
...
Remove the b.active from the WHERE otherwise it will be a condition for the SELECT 从WHERE中删除b.active,否则将成为SELECT的条件
The current queries have SELECT... WHERE ... b.active = 1 ...
meaning it can only return results where that condition is met 当前查询具有
SELECT... WHERE ... b.active = 1 ...
意味着它只能返回满足该条件的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.