Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MYSQL查询-列出在给定距离内未被阻止的事件_Php_Mysql - Fatal编程技术网

Php MYSQL查询-列出在给定距离内未被阻止的事件

Php MYSQL查询-列出在给定距离内未被阻止的事件,php,mysql,Php,Mysql,我有一个非常复杂的查询,它显示所有事件,除了它或它的类别/类型/子类型包含在名为“blocked”的表中的事件。此外,它仅显示活动=1且结束时间介于当前时间和一天结束之间的事件 SELECT e.* FROM `events` e WHERE NOT EXISTS ( SELECT 1 FROM `blocked` b WHERE b.uid = '$uid' AND (e.bid = b.bid OR e.category =

我有一个非常复杂的查询,它显示所有事件,除了它或它的类别/类型/子类型包含在名为“blocked”的表中的事件。此外,它仅显示活动=1且结束时间介于当前时间和一天结束之间的事件

SELECT e.* FROM `events` e WHERE NOT EXISTS (
       SELECT 1 FROM `blocked` b 
              WHERE b.uid = '$uid' 
          AND (e.bid = b.bid OR e.category = b.category 
               OR e.type = b.type OR e.subtype = b.subtype)) 
          AND active = '1' 
          AND end >= '$timeinfo[0]' 
          AND end <= '$timeinfo[2]'
在被阻止的表中,用户001不希望看到出价00a和00h中的任何内容,也不希望看到子类型为“卡拉OK坏歌声”的任何内容。然后,第二个用户002不想看到任何类型栏的内容


我最终要显示的是$mycoords[0]、$mycoords[1]lat/long的$distance英里内的所有事件,除非BID/category/type/subtype被阻止为$uid,按距离排序。如果你们能给我任何帮助,我将不胜感激。

您应该能够简单地将您的距离计算添加到“阻止”检查查询中,以及相关条件

我试图在SQLFIDLE上复制您的示例数据,并将它们组合起来。您可以将用户id修改为001或002以查看不同的结果

为了便于参考,生成的查询是

SELECT e.*,
  ( 3959 * acos( cos( radians(-122.243475) ) * 
            cos( radians( latitude ) ) * cos( radians( longitude ) 
            - radians(33.457573) ) + sin(-122.243475) ) * 
            sin( radians( latitude ) ) )  
       AS distance
  FROM `events` e
  WHERE 
    NOT EXISTS (
       SELECT 1 FROM `blocked` b 
              WHERE b.uid = '001' 
          AND (e.bid = b.bid OR e.category = b.category 
               OR e.type = b.type OR e.subtype = b.subtype)
    ) 
    AND active = '1' 
    AND end >= 1398786400
    AND end <= 1398786400

  HAVING distance < 10000000000000;
请注意,为了示例起见,我不得不删除您的php变量,并执行了以下操作

添加了一些lat/long的示例坐标 添加了一个示例距离 取消限制 添加了一些示例时间 添加了一个示例用户id。
EVENTS: 
  eid | bid | category | type | subtype | latitude | longitude | start | end
  001 | 00a | Nightlife | Bar | Karaoke | 33.457573 | -122.243475 | 1398686400 | 1398786400

BLOCKED: 
  uid | bid | category | type | subtype 
  001 | null | null | null | Karaoke
  001 | 00a | null | null | null
  001 | 00h | null | null | null
  002 | null | null | Bar | null
SELECT e.*,
  ( 3959 * acos( cos( radians(-122.243475) ) * 
            cos( radians( latitude ) ) * cos( radians( longitude ) 
            - radians(33.457573) ) + sin(-122.243475) ) * 
            sin( radians( latitude ) ) )  
       AS distance
  FROM `events` e
  WHERE 
    NOT EXISTS (
       SELECT 1 FROM `blocked` b 
              WHERE b.uid = '001' 
          AND (e.bid = b.bid OR e.category = b.category 
               OR e.type = b.type OR e.subtype = b.subtype)
    ) 
    AND active = '1' 
    AND end >= 1398786400
    AND end <= 1398786400

  HAVING distance < 10000000000000;