Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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-1查询,但返回两个数组';s_Php_Mysql_Arrays - Fatal编程技术网

Php MySQL-1查询,但返回两个数组';s

Php MySQL-1查询,但返回两个数组';s,php,mysql,arrays,Php,Mysql,Arrays,我想知道是否可以向mysql发送一个查询,但接收两个数组的查询 $query = 'SELECT a.username,b.* FROM users a, posts b WHERE b.user_id = a.id'; 这将返回一个数组,如 array( 'postid' => 1, 'title' => 'this is a title', 'body' => 'this is a body', 'user' => array(

我想知道是否可以向mysql发送一个查询,但接收两个数组的查询

$query = 'SELECT a.username,b.* FROM users a, posts b WHERE b.user_id = a.id';
这将返回一个数组,如

array(
    'postid' => 1,
    'title' => 'this is a title',
    'body' => 'this is a body',
    'user' => array(
        'id' => 1,
        'username' => 'name'
    )
)

当前查询返回一个与用户“混合”的数组,并一起发布。

看看MVC模式。 您可以创建一个类似于
Post
的模型,其属性为
postid
title
body
user
作为数组。完成SQL后,可以填充模型。然后可以访问模型中的数据

示例:

class Post {
   private $title;

   public function setTitle($title) {
       $this->title = $title;
   }
   public function getTitle() {
       return $this->title;
   }
}

要获得您想要的查询结果是不可能的

看看MVC模式。 您可以创建一个类似于
Post
的模型,其属性为
postid
title
body
user
作为数组。完成SQL后,可以填充模型。然后可以访问模型中的数据

示例:

class Post {
   private $title;

   public function setTitle($title) {
       $this->title = $title;
   }
   public function getTitle() {
       return $this->title;
   }
}

要获得您想要的查询结果是不可能的

我知道如何限制它,但我的想法是,如果有可能使mysql返回我发送请求的两个表中的单独数组,这是不可能的。就是这样。你必须手动生成数组。我知道如何限制它,但我的想法是,如果有可能让mysql返回我发送请求的两个表中的单独数组,这是不可能的。就这样。你必须手动生成数组。