开发者

Add two array of objects from mysql result

开发者 https://www.devze.com 2023-04-09 19:30 出处:网络
I have a query as follows : $q1 = \" SELECT * FROM tbl_profile WHERE admin_selected = \'y\' \"; $res1 = mysql_query($q1);

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开发者_C百科 of object say $r. How can I do that ?


Why would you like to split it into 2 query statements? You can do it in just one statement.

SELECT * FROM tbl_profile WHERE admin_selected = 'y' OR admin_selected = 'n'

The fetch function will produce an array that holds values of both admin_selected.


you can user following

array_merge($r1,$r2)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号