使用php进行不稳定的MySQL结果

时间:2016-07-09 12:15:55

标签: php mysql

我的PHP和MySQL查询返回错误的信息。

出于此查询的目的 - $ PortalAdvertiserOne和$ PortalAdvertiserTwo是INT

$sql = "
SELECT * 
  FROM 
     ( SELECT * 
         FROM 100_advertisers_campaigns 
        WHERE vendor_owner IN($PortalAdvertiserOne,$PortalAdvertiserTwo)
          AND ad_section_news = 'Y' 
          AND ad_position = 2 
        ORDER 
           BY RAND() 
        LIMIT 1
     ) x 
 ORDER 
    BY ad_id";

查询返回完美的一切,除了" ad_position"应该只返回2的记录,这个查询从我的表中返回1,2,3和4的记录。它似乎没有过滤查询的那部分。

我缺少什么?

1 个答案:

答案 0 :(得分:2)

尝试使用()四舍五入

$sql = "SELECT * FROM (SELECT * FROM 100_advertisers_campaigns WHERE (vendor_owner = $PortalAdvertiserOne or vendor_owner = $PortalAdvertiserTwo and ad_section_news = 'Y') and ad_position = '2' ORDER BY RAND() LIMIT 1) x ORDER BY ad_id";