Salve, ho posto la domanda in database ma visto che non reisco a risolvere, vorrei aggirare il problema in altro modo. IO ho la necessità di estrarre dei dati da un db mysql da due diverse tabelle, volevo evitare i dare due query separate ma visto che non trovo la soluzione, ho pensato di "aggirare" il problema, facendo in questo modo:
Codice PHP:
/* Query 1 */
$sql = "SELECT * FROM tabella 1 WHERE data between '$primo_parametro' and '$secondo_parametro' and id_utente = '$ute' ORDER BY data DESC"; $res = mysql_query($sql);
$data = array();
while ($rows = mysql_fetch_array($res, MYSQL_ASSOC)) { $data[] = $rows; } /* Query 2 */
$sql2 = "SELECT * FROM tabella2 WHERE data_2 between '$primo_parametro' and '$secondo_parametro' and id_utente = '$ute' ORDER BY data_2 DESC"; $res2 = mysql_query($sql2);
$data2 = array();
while ($rows2 = mysql_fetch_array($res2, MYSQL_ASSOC)) { $data2[] = $rows2; }
$combinaData = array_merge($data,$data2); $json = json_encode($combinaData); echo $json;
in questo modo ricevo i dati json in questo formato:
codice:
[ {
"id_tabella1": "1902",
"id_utente": "1",
"data": "2015-05-10",
"Descrizione": "Prodotto 1"
},
{
"id_tabella2": "4",
"id_utente": "1",
"data_2": "2015-05-09",
"Nota": "Nota tabella 2"
}
]
A me invece servirebbero in questo modo:
codice:
[ {
"id_tabella1": "1902",
"id_utente": "1",
"data": "2015-05-10",
"Descrizione": "Prodotto 1",
"id_tabella2": "4",
"id_utente": "1",
"data_2": "2015-05-09",
"Nota": "Nota tabella 2"
}
]
Come potrei fare?