Jump to content

nitrag

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by nitrag

  1. Thanks GKWelding, you set me back on the right track. I was getting myself all confused. Here's the correct code for others: $rs1 = query("SELECT DISTINCT groups.group_ID, group_settings.name FROM groups, group_settings WHERE group_settings.group_ID=groups.group_ID AND groups.group_ID IN (SELECT group_ID FROM groups WHERE user_ID=1)"); $c = 0; $glist = array(); while($row = mysql_fetch_array($rs1)){ $glist[$c] = array('id'=>$row['group_ID'],'name'=>$row['name']); $c++; } $groups['list'] = $glist; $groups['count'] = $c; $rs2 = query("SELECT COUNT(c_ID) FROM contacts WHERE group_ID='$gid'"); $row2 = mysql_fetch_assoc($rs2); $data['cCount'] = $row2['COUNT(c_ID)']; $rs4 = query("SELECT fb_ID FROM users WHERE user_ID IN (SELECT user_ID FROM groups WHERE group_ID='$gid')"); $count = 0; $list = array(); while($row4 = mysql_fetch_array($rs4)){ $list[$count] = $row4['fb_ID']; $count++; } $users = implode(',',$list); $data['users'] = $users; $data['fCount'] = $count-1; //offset for yourself $data['appstoreID'] = '331786748'; $data['groups'] = $groups; $output = json_encode($data); echo $output; Output: { "cCount":"0", "users":"", "fCount":-1, "appstoreID":"331786748", "groups": { "list": [ {"id":"1","name":"Test Group"}, {"id":"2","name":"Ryan's Test Group"} ], "count":2 } }
  2. I'm trying to output some json using PHP's json_encode function. But it seems to add extra quotations which makes it an incorrectly formatted json string...i think. PHP $rs1 = query("SELECT DISTINCT groups.group_ID, group_settings.name FROM groups, group_settings WHERE group_settings.group_ID=groups.group_ID AND groups.group_ID IN (SELECT group_ID FROM groups WHERE user_ID=1)"); $c = 0; $glist = array(); while($row = mysql_fetch_array($rs1)){ $glist[$c] = json_encode(array('id'=>$row['group_ID'],'name'=>$row['name'])); $c++; } $groups['list'] = stripslashes(json_encode($glist)); $groups['count'] = $c; $rs2 = query("SELECT COUNT(c_ID) FROM contacts WHERE group_ID='$gid'"); $row2 = mysql_fetch_assoc($rs2); $data['cCount'] = $row2['COUNT(c_ID)']; $rs4 = query("SELECT fb_ID FROM users WHERE user_ID IN (SELECT user_ID FROM groups WHERE group_ID='$gid')"); $count = 0; $list = array(); while($row4 = mysql_fetch_array($rs4)){ $list[$count] = $row4['fb_ID']; $count++; } $users = implode(',',$list); $data['users'] = $users; $data['fCount'] = $count-1; //offset for yourself $data['appstoreID'] = '331786748'; $data['groups'] = stripslashes(json_encode($groups)); $output = stripslashes(json_encode($data)); echo $output; echo "<br/>"; Output: { "cCount":"0", "users":"", "fCount":-1, "appID":"331786748", "groups": "{" list": "[" {"id":"1","name":"Test Group"}", "{"id":"2","name":"Ryan's Test Group"} "]", "count":2 }" }
  3. if the below outputs correctly $groupcount = '1'; $group1 = 'Yes I work'; $GRP = "group$grpcount"; echo $$GRP; How do I create a class with variable variables. Instead of: $group1 = new Group(); I want to do this same thing with an array of groupX's. Because my user's may have multiple groups and each one needs an instance. $$GRP = new Group(); //I want the above to be the same as: //$group1 = new Group(); //but it's not returning anything
  4. So I recently discovered variable reflection and it's quite handy. Normally I would have $group1, $group2, $group3...etc. But I want to create a foreach loop that gets that ending number and creates the different $groupX from an array. // The below outputs $group1 like I want it to $GRP = "group$groupID"; echo $$GRP; //the below does not work $grpcount = "1"; foreach($user->groupList as $groupID){ $GRP = "group$grpcount"; $$GRP = new Group(); $$GRP->setGroup($groupID); $$GRP->setUser($user->UID); $$GRP->setTab($grpcount); $$GRP->getWidgets(); $$GRP->writeProfile(); $$GRP->writeFullTab(); $$GRP->tab_output; $grpcount++; } Is it because of the foreach or because I cannot set/create a PHP Class with variable reflection. Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.