Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.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
如何在单个数组中同时获得两个数组,而不丢失mysql和php中的值?_Php_Mysql_Arrays - Fatal编程技术网

如何在单个数组中同时获得两个数组,而不丢失mysql和php中的值?

如何在单个数组中同时获得两个数组,而不丢失mysql和php中的值?,php,mysql,arrays,Php,Mysql,Arrays,我从表basic中取出了两个数组,在章节id上。其中一个数组处于章节介于1和6之间的状态。类似地,另一个数组处于相同表中章节介于7到12之间的状态 我的第一个问题在哪里 $sql1 = 'SELECT s.section_number, s.title,n.description,s.global_order_id, c.commentary FROM section as s INNER JOIN note as n INNE

我从表basic中取出了两个数组,在章节id上。其中一个数组处于章节介于1和6之间的状态。类似地,另一个数组处于相同表中章节介于7到12之间的状态

我的第一个问题在哪里

$sql1 = 'SELECT s.section_number, s.title,n.description,s.global_order_id, c.commentary FROM section as s 
                INNER JOIN note as n 
                INNER JOIN commentary as c ON s.global_order_id=n.global_order_id and c.global_order_id=n.global_order_id 
                where n.user_id='.Yii::app()->user->id.' and s.chapter_id Between 1 and 6';
第二个问题是

$sql2 = 'SELECT s.section_number, s.title,n.description,s.global_order_id, c.commentary FROM section as s 
                INNER JOIN note as n 
                INNER JOIN commentary as c ON s.global_order_id=n.global_order_id and c.global_order_id=n.global_order_id 
                where n.user_id=' . Yii::app()->user->id . ' and s.chapter_id Between 7 and 12';
都是一样的,不同的是根据章节的标题

当我进行数组合并时,只会显示一个标题,但我想将双数组变成单数组,并同时显示两个标题。我怎么做


提前感谢…

您可以直接在MySQL中通过
UNION
(隐式区分)或
UNION ALL
这两个查询执行此操作,例如:

SELECT 
  s.section_number,  
  s.title,
  n.description,
  s.global_order_id, 
  c.commentary 
FROM section as s 
INNER JOIN note as n 
INNER JOIN commentary as c  ON s.global_order_id = n.global_order_id 
                           and c.global_order_id = n.global_order_id 
where n.user_id = '.Yii::app()->user->id.' 
  and s.chapter_id Between 1 and 6
UNION ALL
SELECT 
  s.section_number, 
  s.title,
  n.description,
  s.global_order_id, 
  c.commentary 
FROM section as s 
INNER JOIN note as n 
INNER JOIN commentary as c  ON s.global_order_id = n.global_order_id 
                           and c.global_order_id = n.global_order_id 
where n.user_id=' . Yii::app()->user->id . ' 
  and s.chapter_id Between 7 and 12;
然后仅执行此查询,您将把来自此查询的两个结果集合并到一个数组中