far2slow Posted July 21, 2011 Share Posted July 21, 2011 This is the json $gtag = $member['gam_x']; $url = "http://www.oldg.co.uk/xboxapi/xboxapi.php?gtag=".urlencode($gtag); $output = file_get_contents($url); $json = json_decode(utf8_encode($output), true); if($json === null) die("Error parsing JSON response (error #".json_last_error().")."); $online = $json['response'][0]['user']['is_online']; $online_status = $json['response'][0]['user']['online_status']; and i want to call it to 'gamr_x' => $profile['gam_x'], do i just set the json as a function then call it? Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/ Share on other sites More sharing options...
far2slow Posted July 21, 2011 Author Share Posted July 21, 2011 i tryed to make the json script a function then try and call it like 'gamr_x' => $profile['gam_x']. call_user_func('xgamrinfo'), but that wont work any one have any ideas how i can do this the scrip i am running gets members out of a group, lists so this json call is for about 15 users Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245763 Share on other sites More sharing options...
requinix Posted July 21, 2011 Share Posted July 21, 2011 What are you talking about? Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245770 Share on other sites More sharing options...
TeNDoLLA Posted July 21, 2011 Share Posted July 21, 2011 What are you talking about? Was thinking exactly the same... Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245771 Share on other sites More sharing options...
far2slow Posted July 21, 2011 Author Share Posted July 21, 2011 am very sorry i over complicated things in my head what i wanted to do, rather just sitting back and having a think I have about sorted it now Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245786 Share on other sites More sharing options...
phpSensei Posted July 21, 2011 Share Posted July 21, 2011 Far2Slow, you have the first part correct, just repeat the process for that variable you want. Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245807 Share on other sites More sharing options...
far2slow Posted July 21, 2011 Author Share Posted July 21, 2011 i am going to have one last go trying to explain what i am trying to do first part of the code the gamername is the users xbox gamer id while ($profile = $smcFunc['db_fetch_assoc']($query_members)) { $context['display_groups'][$row['place']][$row['id_group']]['members'][$type][] = array( 'id' => $profile['id_member'], 'group_id' => $profile['id_group'] . $gamertag, 'name' => '<span style="color: ' . $row['online_color'] . ';">' . $profile['real_name'] . '</span>', 'colorless_name' => $profile['real_name'], 'gamername' => $profile['gamer_xbgt'], 'href' => $scripturl . '?action=profile;u=' . $profile['id_member'], 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $profile['id_member'] . '"><span style="color: ' . $row['online_color'] . ';">' . $profile['real_name'] . '</span></a>', 'title' => $profile['usertitle'], 'online' => array( 'label' => $txt[$profile['is_online'] ? 'online' : 'offline'], $txt[$profile['is_online'] ? 'online' : 'offline'] . '</a>', 'image_href' => $settings['images_url'] . '/' . ($profile['is_online'] ? 'useron' : 'useroff') . '.gif', ), ); } next bit of the code is the json that that calls the file that scraps the data from xbox.com $gamertag = $member['gamername']; $url = "http://www.oldg.co.uk/xboxapi/xboxapi.php?gamertag=".urlencode($gamertag); $output = file_get_contents($url); $json = json_decode(utf8_encode($output), true); next bit shows prints the data <td align="left" style="padding: 0mm"> <div align="left" style="padding-left: 20px;"> <img src="', $member['online']['image_href'], '" alt="', $member['online']['link'], '" /> <span class="smalltext">', $member['link'], $xboxonline = $json['response'][0]['user']['is_online'], $xboxonline_status = $json['response'][0]['user']['online_status'], '</span><br />'; but i cant get json part to show the data for all the users Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245825 Share on other sites More sharing options...
phpSensei Posted July 21, 2011 Share Posted July 21, 2011 can't you coun't the number of elements in the array, and do a for loop? $xboxonline_status = $json['response'][$counter]['user']['online_status'], Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245829 Share on other sites More sharing options...
far2slow Posted July 21, 2011 Author Share Posted July 21, 2011 not sure if i change the line $gamertag = $member['gamername']; to $gamertag = 'real gamer tag'; i do get a output but its the same for whole list, i have checked that $member['gamername'] is showing the right gamer tag for the user, but if i use it i get nothing been on this for to many hours just cant work it out Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245840 Share on other sites More sharing options...
far2slow Posted July 21, 2011 Author Share Posted July 21, 2011 php sensei i cant cant get that to work either Quote Link to comment https://forums.phpfreaks.com/topic/242547-call-json-to-array/#findComment-1245872 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.