Two SQL queries into the same array
I have two database tables - one for tutors and the other for the subjects
that the tutors teach.
The two are connected by the tutorID. Now I'm trying to get data from both
into a single array. Is there any way to do this? I've tried doing it in
sequence i.e:
$query = "SELECT id, name, avatar, price, ( 3959 * acos( cos(
radians('$center_lat') ) * cos( radians( lat ) ) * cos( radians( lng ) -
radians('$center_lng') ) + sin( radians('$center_lat') ) * sin( radians(
lat ) ) ) ) AS distance
FROM users
having distance < '$radius' order by RAND() LIMIT 0, 20";
$result = mysqli_query($db_conx, $query);
if (!$result) {
echo "Query problem";
}
$rows = array();
//set xml header
/* header("Content-type: application/json"); */
// Iterate through the rows, adding XML nodes for each
while ($r = @mysqli_fetch_assoc($result)){
$rows[] = $r;
}
$tutorID = $rows[0]['id'];
$query = "SELECT level, subject, topic
FROM TUTORLINK
where tutorID='$tutorID'
order by level";
$result = mysqli_query($db_conx, $query);
while ($r = @mysqli_fetch_assoc($result)){
$rows[] = $r;
}
var_dump($rows);
but rows only contains the results of the first query - can anyone help?
No comments:
Post a Comment