
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.46 KB | hits: 14 | expires: Never
JSON Ajax PHP MYSQL - multiple records into JSON
if (mysql_num_rows($pquery) == 1) {
$result = mysql_fetch_assoc($pquery);
$query_ht = mysql_query("SELECT * FROM coupon WHERE pid='$result[id]'");
$ht_result = mysql_fetch_array($query_ht); // THIS WILL ALWAYS RETURN 3 ROWS
//echo json_encode($result); //THis will always contain one row
//echo json_encode($ht_result); // THIS WILL ALWAYS contain 3 ROWS
//echo json_encode(array(
//'comp' => $result,
//'ht' => $ht_result)
// );
$query_htl = mysql_query("SELECT * FROM coupon WHERE pid='$result[id]' AND type='L'");
$query_htg = mysql_query("SELECT * FROM coupon WHERE pid='$result[id]' AND type='G'");
$query_htr = mysql_query("SELECT * FROM coupon WHERE pid='$result[id]' AND type='R'");
$ht_resultl = mysql_fetch_assoc($query_htl);
$ht_resultg = mysql_fetch_assoc($query_htg);
$ht_resultr = mysql_fetch_assoc($query_htr);
echo json_encode(array(
'comp' => $result,
'htL' => $ht_resultl,
'htG' => $ht_resultg,
'htR' => $ht_resultr)
);
}
$('#c_search').submit(function(){
data = ($(this).serialize());
$.ajax({
url: 'actions/get_company.php',
type: 'POST',
data: data,
cache: false,
dataType: 'json',
success: function(selected){
alert(selected.htL.id);
header('Content-type: application/json');
die(json_encode(array(
'result' => $result,
'ht_result' => $ht_result
)));