i have 2 query and i want to combining all of them, i have searched it and found about array merge, my question how to use array merge in proper way, i have tried many times and always error. This is my code
<?php
session_start();
include "config.php";
$viewEO;
$viewAcara;
$ideve=mysql_real_escape_string($_GET["id"]);
$mysql = ("SELECT id_eo,nama as namaEO,logo,deskripsi as DeskEO,email,telp from eventorg WHERE id_eo='$ideve'");
$result=mysql_query($mysql);
if (!empty($result))
{
while ($row=mysql_fetch_array($result))
{
$viewEO[] = array(
'idEO' => $row['id_eo'],
'namaeo' => $row['namaEO'],
'deskripsieo' => $row['DeskEO'],
'email' => $row['email'],
'telpon' => $row['telp'],
'logoeo' => $row['Logo']
);
}
}
$mysql2 = ("SELECT id_acara,nama,tanggal,endtanggal,lokasi,imagePath,deskripsi,id_eo from acara WHERE id_eo='$ideve'");
$result2=mysql_query($mysql2);
if (!empty($result2))
{
while ($row2=mysql_fetch_array($result2))
{
$viewAcara[] = array(
'idacara' => $row2['id_acara'],
'namaacara' => $row2['nama'],
'deskripsi' => $row2['deskripsi'],
'tanggal' => $row2['tanggal']
);
}
}
$final = array_merge(array('array1'=>$viewEO, array('array2'=>$viewAcara)));
mysql_close($con);
header('Content-Type:application/json');
echo json_encode($final);
?>
You don't need array_merge
. Just combine the two arrays into another array:
$final = array('array1'=>$viewEO, 'array2'=>$viewAcara);
header('Content-Type: application/json');
echo json_encode($final);