从 mysql 结果添加两个对象数组
我有一个查询如下:
$q1 = "
SELECT
*
FROM
tbl_profile
WHERE
admin_selected = 'y'
";
$res1 = mysql_query($q1);
$r1 = mysql_fetch_object($res1);
//print_r($r1);
$q2 = "
SELECT
*
FROM
tbl_profile
WHERE
admin_selected = 'n'
";
$res2 = mysql_query($q2);
$r2 = mysql_fetch_object($res2);
//print_r($r2);
?>
现在我想将两个结果 $r1
和 $r2
添加到单个对象数组中,例如 $r
。我怎样才能做到这一点?
I have a query as follows :
$q1 = "
SELECT
*
FROM
tbl_profile
WHERE
admin_selected = 'y'
";
$res1 = mysql_query($q1);
$r1 = mysql_fetch_object($res1);
//print_r($r1);
$q2 = "
SELECT
*
FROM
tbl_profile
WHERE
admin_selected = 'n'
";
$res2 = mysql_query($q2);
$r2 = mysql_fetch_object($res2);
//print_r($r2);
?>
Now I want to add the two results $r1
and $r2
into a single array of object say $r
. How can I do that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么要将其拆分为 2 个查询语句?您只需一个声明就可以做到这一点。
fetch 函数将生成一个数组,其中包含 admin_selected 和 admin_selected 的值。
Why would you like to split it into 2 query statements? You can do it in just one statement.
The fetch function will produce an array that holds values of both admin_selected.
您可以使用以下用户
you can user following