I have two different SELECT queries in php mysql.
I want to combine these two results into one array of objects. I don't want to use SQL UNION because there is some work to be done with the results before the merging.
There is php array_merge() function but when I try to use it, I get the following error:
array_merge(): Argument #1 is not an array
The parameters are the results of a SQL select query.
$result1 = "";
$result2 = "";
$merged_results = "";
$stmt = $db->prepare("SELECT col1, col2 col3 from table1");
$stmt->execute();
$result1 = $stmt->get_result();
$stmt = $db->prepare("SELECT col1, col2 col3 from table2");
$stmt->execute();
$result2 = $stmt->get_result();
$merged_results = array_merge($result1,$result2);
My goal is an array of objects where every object represents a dataset from the mysql select, something like that:
[{name:"Jonny",age:23},{name:"Bonny",age:25},{name:"Flower", age:21}]
so please how to merge these to results into one result of array of objects?
$stmt->bind_param("sss",c1,c2,c3)You're not binding anything and have no parameters.c1,c2,c3?