sql - 条件不起作用的double

时间:2016-06-16 13:10:49

标签: php mysql sql

$sql3 = "SELECT DISTINCT id as id,status as status,'movie-name' as 'key',
moviename as value,poster as cover 
FROM movie 
WHERE id='$movieid' AND status='Coming Soon' 
ORDER BY id DESC LIMIT 6";

似乎不起作用。如果我删除AND status='Coming Soon'则可行。

1 个答案:

答案 0 :(得分:4)

对movie-name和key使用backtic而不是单引号并删除状态别名(因为这可能会在哪里产生问题)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/maps/highmaps.js"></script>
<script src="https://code.highcharts.com/maps/modules/exporting.js"></script>
<script src="https://code.highcharts.com/mapdata/countries/us/us-all.js"></script>
<script src="https://code.highcharts.com/mapdata/countries/us/us-all-all.js"></script>

<div id="container"></div>

如果电影名称是名称而不是列,则使用单引号选择字面值但请记住不要使用不正确的别名,例如状态在哪里

 $sql3 =  "SELECT DISTINCT id ,status ,`movie-name`  as `key`,
             moviename as value,poster as cover 
           FROM movie 
           WHERE id='$movieid' 
           AND status='Coming Soon' 
           ORDER BY id DESC 
           LIMIT 6";