Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 1.68 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. add value to result from mysql query that will be JSON encoded in PHP?
  2. $sth = mysql_query("SELECT tbl_subApp2Tag.*, tbl_tag.* FROM tbl_subApp2Tag LEFT JOIN tbl_tag ON tbl_subApp2Tag.tag_id = tbl_tag.id WHERE tbl_subApp2Tag.subApp_id = '".$sub."' ORDER BY tbl_tag.name ASC");
  3. if(!$sth) echo "Error in query: ".mysql_error();
  4. while($r = mysql_fetch_assoc($sth)) {
  5.     $query = "SELECT * FROM tbl_userDevice2Tag WHERE tag_id='".$r['id']."' AND userDevice_id='".$user."'";
  6.     $result = mysql_query($query) or die(mysql_error());
  7.     if (mysql_num_rows($result)) {
  8.         $r['relation'] = true;
  9.         $rows[] = $r; //Add 'relation' => true to this row
  10.     } else {
  11.         $r['relation'] = false;
  12.         $rows[] = $r; //Add 'relation' => false to this row
  13.     }
  14. }
  15. print json_encode($rows);
  16.        
  17. $sth = mysql_query("
  18.     SELECT
  19.         tbl_subApp2Tag.*,
  20.         tbl_tag.*,
  21.         ISNULL(tbl_userDevice2Tag.userDevice_id) AS relation
  22.  
  23.     FROM tbl_subApp2Tag
  24.     LEFT JOIN tbl_tag
  25.         ON tbl_tag.id = tbl_subApp2Tag.tag_id
  26.  
  27.     LEFT JOIN tbl_userDevice2Tag
  28.         ON tbl_userDevice2Tag.tag_id = tbl_tag.id
  29.         AND tbl_userDevice2Tag.userDevice_id = '".$user."'
  30.  
  31.     WHERE tbl_subApp2Tag.subApp_id = '".$sub."'
  32.     ORDER BY tbl_tag.name ASC
  33. ");
  34.        
  35. $sth = mysql_query("
  36.     SELECT
  37.         tbl_subApp2Tag.*,
  38.         tbl_tag.*,
  39.         ISNULL(tbl_userDevice2Tag.userDevice_id) AS relation
  40.  
  41.     FROM tbl_tag
  42.  
  43.     INNER JOIN tbl_subApp2Tag
  44.         ON tbl_subApp2Tag.tag_id = tbl_tag.id
  45.         AND tbl_subApp2Tag.subApp_id = '".$sub."'
  46.  
  47.     LEFT JOIN tbl_userDevice2Tag
  48.         ON tbl_userDevice2Tag.tag_id = tbl_tag.id
  49.         AND tbl_userDevice2Tag.userDevice_id = '".$user."'
  50.  
  51.     ORDER BY tbl_tag.name ASC
  52. ");