1

I have a call to this php script (only part in question displayed)

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

UPDATE:

   //echo json_encode(array(
       //'comp' => $result,
       //'ht' => $ht_result)
       // );

This works, but I dont think it is pretty..... Any suggestions

  $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)
        );

}

When I am echoing one or the other I am ok.. But i do not know how to return everything to jquery

jquery script:

$('#c_search').submit(function(){
       data = ($(this).serialize());

  $.ajax({
      url: 'actions/get_company.php',
      type: 'POST',
      data: data,
      cache: false,
      dataType: 'json',
      success: function(selected){

i can call with:

alert(selected.htL.id);

1 Answer 1

3

Just combine all results in common array:

header('Content-type: application/json');
die(json_encode(array(
    'result'    => $result,
    'ht_result' => $ht_result
)));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks dfsq for the help. IT has me just about their. I updated the php line above. i get 1 of the rows packed into the array.. should i be using a for each loop to insert all three rows into the array?
First of all, you don't need three queries. In your case use SELECT * FROM coupon WHERE pid='$result[id]' AND type IN ('L', 'G', 'R')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.