Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 从多个具有限制的多对多关系表检索结果_Php_Mysql_Many To Many - Fatal编程技术网

Php 从多个具有限制的多对多关系表检索结果

Php 从多个具有限制的多对多关系表检索结果,php,mysql,many-to-many,Php,Mysql,Many To Many,表关系图像位于此链接中 我使用php作为服务器端编程语言,使用MySQL作为数据库 问题描述 用户添加一个新场地。一个场地可能有多种饮料、活动、特色等。现在,我想要这样一个查询或魔术,这样我就可以从位置表中收集与每个场馆相关的所有饮料、活动、特色、食物、风格、类型、活动选项和空间要求,以及其场馆id、名称、描述、容量、最低费率、最高费率、位置。我还需要偏移和限制结果,以便在后端实现分页。但挑战在于,限制应该限制场馆的数量,而不是饮料、食品、风格等 我还想收集php数组中的结果,如下所示: $re

表关系图像位于此链接中

我使用php作为服务器端编程语言,使用MySQL作为数据库

问题描述

用户添加一个新场地。一个场地可能有多种饮料、活动、特色等。现在,我想要这样一个查询或魔术,这样我就可以从位置表中收集与每个场馆相关的所有饮料、活动、特色、食物、风格、类型、活动选项和空间要求,以及其场馆id、名称、描述、容量、最低费率、最高费率、位置。我还需要偏移和限制结果,以便在后端实现分页。但挑战在于,限制应该限制场馆的数量,而不是饮料、食品、风格等

我还想收集php数组中的结果,如下所示:

$result = array( 0=> array( "name" => "Venue A", "description" => "Venue A description", "capacity" => "Venue A capacity", "location" => "Venue A location", "beverages" => array('beverage1','beverage23','beverage7',...), "events" => array('event8','event17','event19','event4',...), "features" => array('features1',...), "foods" => array(), "styles" => array(), "types" => array('type7', 'type14', 'type23',...), "event_options" => array(), "space_requirements" => array() ) , 1=> array( "name" => "Venue B", "description" => "Venue B description", "capacity" => "Venue B capacity", "location" => "Venue B location", "beverages" => array('beverage1'), "events" => array('event2','event7','event9','event4',...), "features" => array(), "foods" => array(), "styles" => array('style1', 'style2',...), "types" => array('type47', 'type4', 'type3',...), "event_options" => array(), "space_requirements" => array() ) ); 今天是我试图找出解决办法的第五天,但我一直都失败了。下面是MySQL查询的一个片段,我可以写到现在

SELECT v.name, e.event, t.type, s.style FROM venues v LEFT JOIN venue_events ve ON v.venue_id = ve.venue_id LEFT JOIN events e ON e.event_id = ve.event_id LEFT JOIN venue_types vt ON v.venue_id = vt.venue_id LEFT JOIN types t ON t.type_id = vt.type_id LEFT JOIN venue_styles vs ON v.venue_id = vs.venue_id LEFT JOIN styles s ON s.style_id = vs.style_id WHERE v.venue_id IN (SELECT venue_id FROM venues) LIMIT 0,5 /* I want to limit the number of "venues" but the LIMIT 0,5 limits the number of 'events', 'types' , 'styles' the "venue" have. And this is the main problem. I have also tried : WHERE v.venue_id IN (SELECT venue_id FROM venues LIMIT 0,5) but it raises the MySQL error. */ 但是我不知道下一步该怎么做才能得到我上面提到的结果

请帮帮我


谢谢。

子查询中不能使用LIMIT。哦,是的,但我需要有限的结果,任何想法都可以。首先运行内部查询并将其结果嵌入主查询。好的,我知道了,非常感谢。
SELECT DISTINCT ven.venue_id, ven.name, e.event_id, e.event, t.type_id, t.type, s.style_id, s.style

FROM (SELECT * FROM venues v LIMIT 0,5) ven /*This line does magic for me*/

LEFT JOIN venue_events ve ON ven.venue_id = ve.venue_id
LEFT JOIN events e ON e.event_id = ve.event_id

LEFT JOIN venue_types vt ON ven.venue_id = vt.venue_id
LEFT JOIN types t ON t.type_id = vt.type_id

LEFT JOIN venue_styles vs ON ven.venue_id = vs.venue_id
LEFT JOIN styles s ON s.style_id = vs.style_id