Php MySQL-1查询,但返回两个数组';s
我想知道是否可以向mysql发送一个查询,但接收两个数组的查询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(
$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返回我发送请求的两个表中的单独数组,这是不可能的。就这样。你必须手动生成数组。