php - How to access values inside an object? -


{    "http://url.com": {       "id": "http://url.com",       "shares": 11111    } } 

i need access 'id' , 'shares' , seems normal

($results->shares) 

doesn't work here, suggestions? thanks.

edit full code:

<?php   include __dir__ . '/config.php';  function do_curl($start_index, $stop_index) {      // query here pages ids between start index , stop index  $sql = "select * mmakers id >= $start_index , id <= $stop_index"; $result = mysql_query($sql) or die(mysql_error());     while ($row = mysql_fetch_array($result))     {         $fanpages_query[] = 'https://graph.facebook.com/?ids='.$row['domain'];     }     return $fanpages_query;  }   $fanpages = do_curl($_get['start_index'], $_get['stop_index']); $fanpages_count = count($fanpages);   $curl_arr = array(); $master = curl_multi_init();  for($i = 0; $i < $fanpages_count; $i++) {     $url = $fanpages[$i];     $curl_arr[$i] = curl_init($url);     curl_setopt($curl_arr[$i], curlopt_returntransfer, true);     curl_multi_add_handle($master, $curl_arr[$i]); } {     curl_multi_exec($master,$running); } while($running > 0);   for($i = 0; $i < $fanpages_count; $i++) {     $results = json_decode(curl_multi_getcontent($curl_arr[$i]));      $sql_mm = "select * mmakers domain='".($results->id)."'";     $result_mm = mysql_query($sql_mm) or die(mysql_error());     $row_mm = mysql_fetch_array($result_mm);      if ($row_mm['type'] == 'auto') {     $sql_d = "select domain domains_list used='no' , directory='".$row_mm['directory']."' , type='auto' order rand() limit 1";     $result_d = mysql_query($sql_d) or die(mysql_error());     $row_d = mysql_fetch_array($result_d);     } else {     $sql_d = "select domain domains_list used='no' , directory='".$row_mm['directory']."' , type='jaa' order rand() limit 1";     $result_d = mysql_query($sql_d) or die(mysql_error());     $row_d = mysql_fetch_array($result_d);     }      mysql_query("update mmakers set shares = '".($results->shares)."' id='".$row_mm['id']."'") or die(mysql_error());  }  ?> 

i suggest decode json array:

$results = json_decode($json, true); 

then assuming don't know url, have loop on array:

foreach($results $url => $data) {     echo $url, ' shares: ', $data['shares']; } 

if know url, can do

$results['http://url.com']['shares']; 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -