Jump to content

Search the Community

Showing results for tags 'json'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. http://paste.ee/p/OhiWv The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working. <script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script>
  2. Hey Guys & Girls, Okay, so here's my little issue. I'm running a WordPress site with a custom PHP script using JSON/CURL/API pulling info from an API. All is good in the world in this respect. However, the API listings that are returned are only returned in a 50 item block. The API doesn't allow for more than 50 items per call. So, what I'm looking for is a way to paginate my results so that if there are more than 50 items in the API call, it will allow the user to click to page 2, 3, 4 etc. Here's my code: <?php //functions relating to wordpress go here: //---------------------------------------- $bg_colors = array('green', 'orange', 'blue', 'yellow', 'red', 'black'); //---------------------------------------- //End functions relating to wordpress // Start PetRescue PHP/API Code //---------------------------------------- // Open CuRL/JSON Stuff $ch = curl_init(); $category=$_GET['category']; $url="http://www.myapilink.com.au/api/listings?token=f716909f5d644fe3702be5c7895aa34e&group_id=10046&species=".$category; curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: application/json', 'X-some-API-Key: f716909f5d644fe3702be5c7895aa34e', )); $json = json_decode(curl_exec($ch), true); // Functions relating to the Echo Code foreach($json['listings'] as $listing) { $short_personality=substr($listing['personality'],0,500); $peturl="http://mysiteurl.com.au/beta/pet-info/?petid=".$listing['id']; $medium_photo=$listing['photos'][0]['large_340']; $gallery_listing=$listing['photos'][5]['large_900']; $gender_class=strtolower($listing['gender']); $breed_class=strtolower($listing['species']); $name=($listing['name']); $unique_gallery_name="lightbox['.$inc.']"; $inc++; foreach($listing["photos"] as $photosthumb) { $photo_thumb_large=$photosthumb["large_340"]; $photo_thumb_hidden=$photosthumb["small_80"]; } $rand_background = $bg_colors[array_rand($bg_colors)]; // General IF/AND/ELSE Statements to refine the Echo Output if($listing['photos'] == null) { $medium_photo="http://mysiteurl.com.au/beta/wp-content/themes/Archive/images/photo_coming_soon.png"; } if($listing['desexed'] == "Yes") { $desexed="yes"; } else { $desexed="no"; } if($listing['vaccinated'] == "Yes") { $vaccinated="yes"; } else { $vaccinated="no"; } if($listing['wormed'] == "Yes") { $wormed="yes"; } elseif($listing['wormed'] == "No") { $wormed="no"; } else { $wormed="no"; } if($listing['heart_worm_treated'] == "Yes") { $heart_worm_tested="yes"; } elseif($listing['heart_worm_treated'] == "No") { $heart_worm_tested="no"; } else { $heart_worm_tested="no"; } if($listing['species'] == "Dog") { $adoption_enquiry_link="http://mysiteurl.com.au/beta/pre-adoption-form-dogs/?dog_name=$name"; $hwt="list-$heart_worm_tested"; } elseif($listing['species'] == "Cat") { $adoption_enquiry_link="http://mysiteurl.com.au/beta/pre-adoption-form-cats/?cat_name=$name"; $hwt="list-hwt-hidden"; } // Echo the output echo'<div class="animal"> <div class="animal-image"> <a class="size-thumbnail thickbox" rel="'.$unique_gallery_name.'" href="'.$medium_photo.'"> <img src="'.$medium_photo.'" class="image-with-border" alt=""> <div class="border" style="width: 340px; height: 340px;"> <div class="open"></div> </div> </a> <div class="item-title-bg '.$rand_background.'"> <h2 class="entry-title">'.$listing['name'].'</h2> <div class="animal-adopt-button"> <a href="'.$adoption_enquiry_link.'" style="background-color: #575757; border-color: #494949; background-position:5px 0;" class="button medium">Enquire about '.$name.'</a> </div> </div> </div> <div class="animal-thumbnail hidden"> <a class="lightbox" rel="'.$unique_gallery_name.'" href="'.$photo_thumb_large.'"> <img class="animal-thumbnail" src="'.$photo_thumb_hidden.'" > </a> </div> <div class="animal-content"> <div class="animal-left"> <ul class="animal-list"> <li class="list-sex-'.$gender_class.'">'.$listing['gender'].'</li> <li class="list-breed-'.$breed_class.'">'.$listing['breeds_display'].'</li> <li class="list-age">'.$listing['age'].'</li> <li class="list-fee">'.$listing['adoption_fee'].'</li> </ul> </div> <div class="animal-right"> <ul class="animal-list"> <li class="list-'.$desexed.'">Desexed?</li> <li class="list-'.$vaccinated.'">Vaccinated?</li> <li class="list-'.$wormed.'">Wormed?</li> <li class="'.$hwt.'">Heart Worm Tested?</li> </ul> </div> <div class="animal-full"> <ul class="animal-list"> <li class="list-description">'.$listing['personality'].'</li> </ul> </div></div> <div class="clearer"></div> </div> <div class="delimiter"></div>'; // Close the CURL } curl_close($ch); ?> Attached is some dummy data that represents the JSON data returned from the API. As you can see in the file, the last line is where the paging details comes in. Any help you guys could give would be appreciated. Cheers, Dave listings.txt
  3. Hello guys I Have to try to build an array that has a tree structure(4 levels), but I have gotten an error when I tried to put the 2 level ... commands out of sync; you can't run this command now. I attached a file with the code, what's wrong? Regards. code.txt
  4. Hi guys, I am trying to build a simple web app that takes data from database, converts it into jason and inserts the data into a veriable that should act as a playlist. I want to make the veriable called "songs" to be equals the result and insert it into ytplayer_playlist. Any guides will be very helpfull! var songs; function addsongs(event) { $.ajax({ url: 'post.php', success: function (response) { var url="http://localhost/xampp/websites/youtubeAPI/post.php"; $.getJSON(url,function(data){ $.each(data.members, function(i,song){ result = (song.SongUrl); console.log(result); }); }); } }); } ytplayer_playlist.push('tGvHNNOLnCk');
  5. Hi everyone, let me first preface this by saying that I know very little about php and json. What I know is that I need a webpage that can provide specific weather data for a group of coxswains using their cellphones while out on patrol. Don't worry that you might be talking down to me, because I promise that you won't be when it comes to my codeing skills. That said, I created an API key for weather underground. This provides me with a json file like this: { "response": { "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features": { "conditions": 1 , "tide": 1 } } , "current_observation": { "image": { "url":"http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png", "title":"Weather Underground", "link":"http://www.wunderground.com" }, "display_location": { "full":"Marcus Hook, PA", "city":"Marcus Hook", "state":"PA", "state_name":"Pennsylvania", "country":"US", "country_iso3166":"US", "zip":"19060", "magic":"3", "wmo":"99999", "latitude":"39.83526230", "longitude":"-75.44973755", "elevation":"28.00000000" }, "observation_location": { "full":"Radnor Green, Claymont, Delaware", "city":"Radnor Green, Claymont", "state":"Delaware", "country":"US", "country_iso3166":"US", "latitude":"39.806858", "longitude":"-75.468452", "elevation":"129 ft" }, "estimated": { }, "station_id":"KDECLAYM2", "observation_time":"Last Updated on January 17, 1:48 PM EST", "observation_time_rfc822":"Fri, 17 Jan 2014 13:48:43 -0500", "observation_epoch":"1389984523", "local_time_rfc822":"Fri, 17 Jan 2014 13:48:43 -0500", "local_epoch":"1389984523", "local_tz_short":"EST", "local_tz_long":"America/New_York", "local_tz_offset":"-0500", "weather":"Scattered Clouds", "temperature_string":"41.7 F (5.4 C)", "temp_f":41.7, "temp_c":5.4, "relative_humidity":"67%", "wind_string":"From the South at 2.0 MPH Gusting to 4.0 MPH", "wind_dir":"South", "wind_degrees":186, "wind_mph":2.0, "wind_gust_mph":"4.0", "wind_kph":3.2, "wind_gust_kph":"6.4", "pressure_mb":"1014", "pressure_in":"29.94", "pressure_trend":"-", "dewpoint_string":"32 F (-0 C)", "dewpoint_f":32, "dewpoint_c":-0, "heat_index_string":"NA", "heat_index_f":"NA", "heat_index_c":"NA", "windchill_string":"42 F (5 C)", "windchill_f":"42", "windchill_c":"5", "feelslike_string":"42 F (5 C)", "feelslike_f":"42", "feelslike_c":"5", "visibility_mi":"10.0", "visibility_km":"16.1", "solarradiation":"--", "UV":"2","precip_1hr_string":"0.00 in ( 0 mm)", "precip_1hr_in":"0.00", "precip_1hr_metric":" 0", "precip_today_string":"0.00 in (0 mm)", "precip_today_in":"0.00", "precip_today_metric":"0", "icon":"partlycloudy", "icon_url":"http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", "forecast_url":"http://www.wunderground.com/US/PA/Marcus_Hook.html", "history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KDECLAYM2", "ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=39.806858,-75.468452" } , "tide": { "tideInfo": [ { "tideSite":"Marcus Hook, Pennsylvania (sub)", "lat":"39.8117", "lon":"-75.4117", "units":"feet", "type":"tide", "tzname":"America/New_York" } ], "tideSummary": [ { "date": { "pretty": "5:03 PM EST on January 17, 2014", "year": "2014", "mon": "01", "mday": "17", "hour": "17", "min": "03", "tzname": "America/New_York", "epoch":"1389996218" }, "utcdate": { "pretty": "10:03 PM GMT on January 17, 2014", "year": "2014", "mon": "01", "mday": "17", "hour": "22", "min": "03", "tzname": "UTC", "epoch":"1389996218" }, "data": { "height":"", "type":"Sunset" } }, { "date": { "pretty": "6:48 PM EST on January 17, 2014", "year": "2014", "mon": "01", "mday": "17", "hour": "18", "min": "48", "tzname": "America/New_York", "epoch":"1390002484" }, "utcdate": { "pretty": "11:48 PM GMT on January 17, 2014", "year": "2014", "mon": "01", "mday": "17", "hour": "23", "min": "48", "tzname": "UTC", "epoch":"1390002484" }, "data": { "height":"", "type":"Moonrise" } }, { "date": { "pretty": "8:09 PM EST on January 17, 2014", "year": "2014", "mon": "01", "mday": "17", "hour": "20", "min": "09", "tzname": "America/New_York", "epoch":"1390007349" }, "utcdate": { "pretty": "1:09 AM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "01", "min": "09", "tzname": "UTC", "epoch":"1390007349" }, "data": { "height":"-0.39 ft", "type":"Low Tide" } }, { "date": { "pretty": "1:23 AM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "01", "min": "23", "tzname": "America/New_York", "epoch":"1390026202" }, "utcdate": { "pretty": "6:23 AM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "06", "min": "23", "tzname": "UTC", "epoch":"1390026202" }, "data": { "height":"4.78 ft", "type":"High Tide" } }, { "date": { "pretty": "7:19 AM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "07", "min": "19", "tzname": "America/New_York", "epoch":"1390047590" }, "utcdate": { "pretty": "12:19 PM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "12", "min": "19", "tzname": "UTC", "epoch":"1390047590" }, "data": { "height":"", "type":"Sunrise" } }, { "date": { "pretty": "8:12 AM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "08", "min": "12", "tzname": "America/New_York", "epoch":"1390050752" }, "utcdate": { "pretty": "1:12 PM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "13", "min": "12", "tzname": "UTC", "epoch":"1390050752" }, "data": { "height":"-0.39 ft", "type":"Low Tide" } }, { "date": { "pretty": "8:19 AM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "08", "min": "19", "tzname": "America/New_York", "epoch":"1390051164" }, "utcdate": { "pretty": "1:19 PM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "13", "min": "19", "tzname": "UTC", "epoch":"1390051164" }, "data": { "height":"", "type":"Moonset" } }, { "date": { "pretty": "1:36 PM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "13", "min": "36", "tzname": "America/New_York", "epoch":"1390070194" }, "utcdate": { "pretty": "6:36 PM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "18", "min": "36", "tzname": "UTC", "epoch":"1390070194" }, "data": { "height":"5.26 ft", "type":"High Tide" } }, { "date": { "pretty": "5:04 PM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "17", "min": "04", "tzname": "America/New_York", "epoch":"1390082683" }, "utcdate": { "pretty": "10:04 PM GMT on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "22", "min": "04", "tzname": "UTC", "epoch":"1390082683" }, "data": { "height":"", "type":"Sunset" } }, { "date": { "pretty": "7:44 PM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "19", "min": "44", "tzname": "America/New_York", "epoch":"1390092273" }, "utcdate": { "pretty": "12:44 AM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "00", "min": "44", "tzname": "UTC", "epoch":"1390092273" }, "data": { "height":"", "type":"Moonrise" } }, { "date": { "pretty": "8:47 PM EST on January 18, 2014", "year": "2014", "mon": "01", "mday": "18", "hour": "20", "min": "47", "tzname": "America/New_York", "epoch":"1390096073" }, "utcdate": { "pretty": "1:47 AM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "01", "min": "47", "tzname": "UTC", "epoch":"1390096073" }, "data": { "height":"-0.36 ft", "type":"Low Tide" } }, { "date": { "pretty": "2:02 AM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "02", "min": "02", "tzname": "America/New_York", "epoch":"1390114947" }, "utcdate": { "pretty": "7:02 AM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "07", "min": "02", "tzname": "UTC", "epoch":"1390114947" }, "data": { "height":"4.76 ft", "type":"High Tide" } }, { "date": { "pretty": "7:19 AM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "07", "min": "19", "tzname": "America/New_York", "epoch":"1390133959" }, "utcdate": { "pretty": "12:19 PM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "12", "min": "19", "tzname": "UTC", "epoch":"1390133959" }, "data": { "height":"", "type":"Sunrise" } }, { "date": { "pretty": "8:49 AM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "08", "min": "49", "tzname": "America/New_York", "epoch":"1390139365" }, "utcdate": { "pretty": "1:49 PM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "13", "min": "49", "tzname": "UTC", "epoch":"1390139365" }, "data": { "height":"", "type":"Moonset" } }, { "date": { "pretty": "8:53 AM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "08", "min": "53", "tzname": "America/New_York", "epoch":"1390139590" }, "utcdate": { "pretty": "1:53 PM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "13", "min": "53", "tzname": "UTC", "epoch":"1390139590" }, "data": { "height":"-0.37 ft", "type":"Low Tide" } }, { "date": { "pretty": "2:14 PM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "14", "min": "14", "tzname": "America/New_York", "epoch":"1390158882" }, "utcdate": { "pretty": "7:14 PM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "19", "min": "14", "tzname": "UTC", "epoch":"1390158882" }, "data": { "height":"5.18 ft", "type":"High Tide" } }, { "date": { "pretty": "5:05 PM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "17", "min": "05", "tzname": "America/New_York", "epoch":"1390169151" }, "utcdate": { "pretty": "10:05 PM GMT on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "22", "min": "05", "tzname": "UTC", "epoch":"1390169151" }, "data": { "height":"", "type":"Sunset" } }, { "date": { "pretty": "8:41 PM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "20", "min": "41", "tzname": "America/New_York", "epoch":"1390182096" }, "utcdate": { "pretty": "1:41 AM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "01", "min": "41", "tzname": "UTC", "epoch":"1390182096" }, "data": { "height":"", "type":"Moonrise" } }, { "date": { "pretty": "9:25 PM EST on January 19, 2014", "year": "2014", "mon": "01", "mday": "19", "hour": "21", "min": "25", "tzname": "America/New_York", "epoch":"1390184750" }, "utcdate": { "pretty": "2:25 AM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "02", "min": "25", "tzname": "UTC", "epoch":"1390184750" }, "data": { "height":"-0.37 ft", "type":"Low Tide" } }, { "date": { "pretty": "2:41 AM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "02", "min": "41", "tzname": "America/New_York", "epoch":"1390203660" }, "utcdate": { "pretty": "7:41 AM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "07", "min": "41", "tzname": "UTC", "epoch":"1390203660" }, "data": { "height":"4.78 ft", "type":"High Tide" } }, { "date": { "pretty": "7:18 AM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "07", "min": "18", "tzname": "America/New_York", "epoch":"1390220326" }, "utcdate": { "pretty": "12:18 PM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "12", "min": "18", "tzname": "UTC", "epoch":"1390220326" }, "data": { "height":"", "type":"Sunrise" } }, { "date": { "pretty": "9:18 AM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "09", "min": "18", "tzname": "America/New_York", "epoch":"1390227517" }, "utcdate": { "pretty": "2:18 PM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "14", "min": "18", "tzname": "UTC", "epoch":"1390227517" }, "data": { "height":"", "type":"Moonset" } }, { "date": { "pretty": "9:34 AM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "09", "min": "34", "tzname": "America/New_York", "epoch":"1390228453" }, "utcdate": { "pretty": "2:34 PM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "14", "min": "34", "tzname": "UTC", "epoch":"1390228453" }, "data": { "height":"-0.36 ft", "type":"Low Tide" } }, { "date": { "pretty": "2:53 PM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "14", "min": "53", "tzname": "America/New_York", "epoch":"1390247607" }, "utcdate": { "pretty": "7:53 PM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "19", "min": "53", "tzname": "UTC", "epoch":"1390247607" }, "data": { "height":"5.10 ft", "type":"High Tide" } }, { "date": { "pretty": "5:07 PM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "17", "min": "07", "tzname": "America/New_York", "epoch":"1390255620" }, "utcdate": { "pretty": "10:07 PM GMT on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "22", "min": "07", "tzname": "UTC", "epoch":"1390255620" }, "data": { "height":"", "type":"Sunset" } }, { "date": { "pretty": "9:39 PM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "21", "min": "39", "tzname": "America/New_York", "epoch":"1390271968" }, "utcdate": { "pretty": "2:39 AM GMT on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "02", "min": "39", "tzname": "UTC", "epoch":"1390271968" }, "data": { "height":"", "type":"Moonrise" } }, { "date": { "pretty": "10:04 PM EST on January 20, 2014", "year": "2014", "mon": "01", "mday": "20", "hour": "22", "min": "04", "tzname": "America/New_York", "epoch":"1390273452" }, "utcdate": { "pretty": "3:04 AM GMT on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "03", "min": "04", "tzname": "UTC", "epoch":"1390273452" }, "data": { "height":"-0.40 ft", "type":"Low Tide" } }, { "date": { "pretty": "3:19 AM EST on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "03", "min": "19", "tzname": "America/New_York", "epoch":"1390292379" }, "utcdate": { "pretty": "8:19 AM GMT on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "08", "min": "19", "tzname": "UTC", "epoch":"1390292379" }, "data": { "height":"4.83 ft", "type":"High Tide" } }, { "date": { "pretty": "7:18 AM EST on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "07", "min": "18", "tzname": "America/New_York", "epoch":"1390306692" }, "utcdate": { "pretty": "12:18 PM GMT on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "12", "min": "18", "tzname": "UTC", "epoch":"1390306692" }, "data": { "height":"", "type":"Sunrise" } }, { "date": { "pretty": "9:47 AM EST on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "09", "min": "47", "tzname": "America/New_York", "epoch":"1390315667" }, "utcdate": { "pretty": "2:47 PM GMT on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "14", "min": "47", "tzname": "UTC", "epoch":"1390315667" }, "data": { "height":"", "type":"Moonset" } }, { "date": { "pretty": "10:18 AM EST on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "10", "min": "18", "tzname": "America/New_York", "epoch":"1390317480" }, "utcdate": { "pretty": "3:18 PM GMT on January 21, 2014", "year": "2014", "mon": "01", "mday": "21", "hour": "15", "min": "18", "tzname": "UTC", "epoch":"1390317480" }, "data": { "height":"-0.34 ft", "type":"Low Tide" } } ], "tideSummaryStats": [ { "maxheight":5.260000, "minheight":-0.400000 } ] } } I wrote a php script like this to parse the data that I need and display it: <!DOCTYPE html> <html> <body> <?php $json_string = file_get_contents("http://api.wunderground.com/api/<key removed for this post>/conditions/tide/q/PA/Marcus_hook.json"); $parsed_json = json_decode($json_string); $wlocation = $parsed_json->{'current_observation'}->{'display_location'}->{'full'}; $temp_f = $parsed_json->{'current_observation'}->{'temp_f'}; $humid = $parsed_json->{'current_observation'}->{'relative_humidity'}; $wind = $parsed_json->{'current_observation'}->{'wind_string'}; $pressure = $parsed_json->{'current_observation'}->{'pressure_mb'}; $pressuretrend = $parsed_json->{'current_observation'}->{'pressure_trend'}; $feels = $parsed_json->{'current_observation'}->{'feelslike_string'}; $wtime = $parsed_json->{'current_observation'}->{'observation_time_rfc822'}; $tlocation = $parsed_json->{'tide'}->{'tideinfo'}->{'tidesite'}; /* $temp_f = $parsed_json->{'current_observation'}->{'temp_f'}; $humid = $parsed_json->{'current_observation'}->{'relative_humidity'}; $wind = $parsed_json->{'current_observation'}->{'wind_string'}; $pressure = $parsed_json->{'current_observation'}->{'pressure_mb'}; $pressuretrend = $parsed_json->{'current_observation'}->{'pressure_trend'}; $feels = $parsed_json->{'current_observation'}->{'feelslike_string'}; $wtime = $parsed_json->{'current_observation'}->{'observation_time_rfc822'};*/ echo "Current temperature in ${wlocation} is: ${temp_f} F, but it feels like ${feels}<BR>"; echo "The current humidity is ${humid}<BR>"; echo "The winds are ${wind}<BR>"; if ($pressuretrend == "+") { echo "The current pressure is ${pressure} and rising <BR>"; } else { echo "The current pressure is ${pressure} and falling <BR>"; } echo "This weather report last updated ${wtime} <BR>"; echo "<Hr>"; echo "<BR>"; ?> </body> </html> Which prints out a nice report like this: What I can't figure out, as in completely and hopelessly lost, is how in the world to get it to make a table of the tides. The json file, for example, uses "pretty" over and over again. I need it to find EACH instance of "pretty" and add it to the tide chart, not just one. I hope I'm clear on what I'm trying to do. If not, please ask questions, just keep in mind that I'm a coding infant!
  6. I'm trying to accessing value from json api instagram. I've successed to access simple api that returns like this: { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } Since im trying to tricky the API to get all user media in one account, i combine API and next pagination api in one file named cache.json. Now it looks like this: { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } { "pagination": { }, "meta": { "code": 200 }, "data": [ { "attribution": null, "tags": [ ], "type": "image", "location": null, "comments": { "count": 0, "data": [ ] }, "filter": "Normal", "created_time": "1339298544", "link": "http:\/\/instagram.com\/p\/LrZfG6sU_l\/", "likes": { "count": 0, "data": [ ] }, "images": { "low_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_6.jpg", "width": 306, "height": 306 }, "thumbnail": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_5.jpg", "width": 150, "height": 150 }, "standard_resolution": { "url": "http:\/\/distilleryimage5.s3.amazonaws.com\/7f69259cb2ab11e1989612313815112c_7.jpg", "width": 612, "height": 612 } }, "users_in_photo": [ ], "caption": null, "user_has_liked": false, "id": "210373896496566245_180213154", "user": { "username": "realwahyuputra", "website": "", "profile_picture": "http:\/\/images.ak.instagram.com\/profiles\/profile_180213154_75sq_1359089013.jpg", "full_name": "realwahyuputra", "bio": "", "id": "180213154" } } ] } How to accessing that value in PHP? There are three data value either when the simple api just one data value. Im using this code to accessing that value but doesn't worked: $cache = './cache.json'; $response = json_decode(file_get_contents($cache),true); //Decode as an json array if(is_array($response['data'])){ foreach ($response['data'] as $data) { if ($data['comments']['data'] != null) { foreach($data['comments']['data'] as $comment){ ...
  7. I am trying to create a search query for either the YearBuilt (yachts.theskywatergroup.com/yatco_data_feeds/datafeed_customer/query2.php) or LocationState a Vessel is located in (yachts.theskywatergroup.com/yatco_data_feeds/datafeed_customer/query3.php.) See attached files. I can only get the full return of the URI. I am not fluent in PHP coding as I am more involved in web design, graphics, emarketing, etc., but want to learn this for one of my friend's who is a Yacht broker. Part of the example response data from the "Search" URI is below. A few questions as this is new to me - 1 - What are the numbers and "String content" in JSON? 2 - Can $_Get('City') be a request from a form? 3 - Is it my code in the attached files or is there something else I need from the providing Dataservice? { "PageCount":"2147483647, "RecordCount":2147483647, "Vessels":[( "AskingPriceFormatted":"String content", "City":"String content", "VesselID":2147483647, "YearBuilt":2147483647 )] } query3.php query_results3.php query_results2.php query2.php
  8. Hey everyone, I'm trying to send a JSON array to an API via HTTP POST, get a response and print it. I tried using cURL to do so, but it doesn't seem to work. I simply get zero response, a blank page. My request: <?php $data = array( "login" => "myLogin", "password" => "myPassword", "id" => "12345", "tag" => "test" ); $json_data = json_encode($data); $ch = curl_init('URL/api/mylogin'); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($json_data)) ); $output = curl_exec($ch); $result = json_decode($output); echo $result; ?> The response I should be getting: {"status": 200, "message": "OK", "login_key": "abcdefh532h235yh"} any idea why I'm not getting any response? (this works ok when I manually test it using a test REST client) Thanks, Rani
  9. Below is PHP using CURL with JSON to POST data to the MemberClicks API. I keep getting a 413 error when trying to process the page. I've tried a few things, but none seem to work. So far I don't get and syntax errors just on the 413. <?php if (!empty($_POST['userid']) && !empty($_POST['username']) && $_POST['data']=="Update") { $dateATOM = date(DATE_ATOM); $groupid = "12345"; $org = "ABCco"; $userid = $_POST['userid']; $username = $_POST['username']; $contactname = $_POST['contactname']; $email = $_POST['email']; $firstname = $_POST['firstname']; $middlename = $_POST['middlename']; $lastname = $_POST['lastname']; $businessaddress1 = $_POST['businessaddress1']; $businessaddress2 = $_POST['businessaddress2']; $businesscity = $_POST['businesscity']; $businessstate = $_POST['businessstate']; $businessinternationalstate = $_POST['businessinternationalstate']; $businesscountry = $_POST['businesscountry']; $businesszip = $_POST['businesszip']; $companyname = $_POST['companyname']; $title = $_POST['title']; $businessphone = $_POST['businessphone']; $mobilephone = $_POST['mobilephone']; $extension = $_POST['extension']; $fax = $_POST['fax']; $url = $_POST['url']; // Establish $url = 'https://####.memberclicks.net/services/auth'; $data = 'apiKey=123&username=user&password=pass'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $httpHeaders[] = "Accept: application/json"; curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders); curl_close($ch); $token = $jsonResult->token; // end --> $raw_json ='{"userId": "'.$userid.'","groupId":"'.$groupid.'","orgId":"'.$org.'","contactName": "'.$contactname.'","userName": "'.$username.'","attribute":[{"userId": "'.$userid.'","attId":"528954","attTypeId":"10", "attData": "'.$username.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"528955","attTypeId":"16", "attData": "'.$contactname.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"528950","attTypeId":"1", "attData": "'.$email.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529209","attTypeId":"2", "attData": "'.$firstname.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529210","attTypeId":"7", "attData": "'.$middlename.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529211","attTypeId":"3", "attData": "'.$lastname.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529213","attTypeId":"28", "attData": "'.$businessaddress1.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529214","attTypeId":"29", "attData": "'.$businessaddress2.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529215","attTypeId":"30", "attData": "'.$businesscity.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529216","attTypeId":"31", "attData": "'.$businessstate.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529240","attTypeId":"7", "attDate": "'.$businessinternationalstate.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529217","attTypeId":"33", "attData": "'.$businesscountry.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529218","attTypeId":"32", "attData": "'.$businesszip.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529219","attTypeId":"7", "attData": "'.$companyname.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529220","attTypeId":"7", "attData": "'.$title.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529221","attTypeId":"5", "attData": "'.$businessphone.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529244", "attData": "'.$mobilephone.'","attTypeId":"5","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529222","attName":"Extension", "attData": "'.$extension.'","lastModify": "'.$dateATOM.'"},{"userId": "'.$userid.'","attId":"529223","attTypeId":"14", "attData": "'.$fax.'","lastModify": "'.$dateATOM.'"}, {"userId": "'.$userid.'","attId":"529228","attTypeId":"15", "attData": "'.$url.'","lastModify": "'.$dateATOM.'"}]}'; $json = json_decode($raw_json); $url2 = 'https://####.memberclicks.net/services/user/'.$userid.'/?includeAtts=true'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url2); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_POST, true); $httpHeaders[] = "Accept: application/json"; $httpHeaders[] = "Authorization: ".$token; curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders ); curl_setopt($ch, CURLOPT_FAILONERROR, true); $results = curl_exec($ch); if (curl_errno($ch)) { echo "<h2>Yes</h2>"; print "<strong>".curl_getinfo( $ch, CURLINFO_HTTP_CODE )."</strong><br><br>"; print "<strong>".curl_error($ch)."</strong><br><br>"; echo "<hr><p>".var_dump($json)."</p>"; } else { echo "<h2>No</h2>"; print curl_getinfo( $ch, CURLINFO_HTTP_CODE ); curl_close($ch); echo "<hr><p>".var_dump($json)."</p>"; //print curl_error($ch); //echo "<p>".$raw_json."</p>"; //header("location: getAll.php?error=Something Happened!"); } return $results; } else { header("location: getAll.php?error=Nothing Happened!"); } ?>
  10. Good evening! I'm new in the forum and programming php! I'm trying to create an application with jqmobile. From the following I obtain results from db mysql but I obtain value "null" when there are special characters like ò, à, è, ù ... Is it possible to replace the special characters? THANKS!!! <?php include 'config.php'; $sql = "SELECT * FROM table_books WHERE info5 = 'thriller' ORDER BY id DESC"; try { $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $dbh->query($sql); $employees = $stmt->fetchAll(PDO::FETCH_OBJ); $dbh = null; echo '{"items":'. json_encode($employees) .'}'; } catch(PDOException $e) { echo '{"error":{"text":'. $e->getMessage() .'}}'; } ?>
  11. Sorry I think my topic question is weird but just want to make the wordings as less as possible. I read a few of the threads but none of them seem to match what I need. What I'm trying to do it something like a voting system but does not include mysql at the moment. I made three radio buttons of music types pop, rock, metallic and a submit so whichever a person choose either one of them and submit the data is wrote into a data.json and stored there. Then I have a page to load all the data in data.json file but I want to count how many people selected for example metallic and how many people selected rock. at the moment I'm still testing and I actually thought of an idea but somehow searched up and not getting what I want.....can someone give me a hand? this is my data.json file {"type":"metallic"} {"type":"pop"} {"type":"metallic"} and this is what my result code is at the moment <?php $file = fopen('data.json', "r"); $array_record = array(); while(!feof($file)) { $line = fgets($file); $data = json_decode($line, TRUE); if (is_array($data)) { foreach ($data as $key => $value) { // echo $key.'='.$value.' '; // show key=value pairs $array_record += array($value,); var_dump($data); print_r($data); echo $value; } echo '<br>'.PHP_EOL; } } fclose($file); ?> I know the codes are messy because I tried setting up an empty array first then get the $value which is something like metallic into an array so I can use the array_count_values but the way I'm doing it seems totally wrong or that'd never work. I tried few other ways to get only metallic/pop so I can try counting the same thing. Thanks in advance.
  12. Hello, I'm trying to retrieve dates from the database based on a selection. If a user selects singer A for example, then I'm going through the database and get the unavailable dates of singer A. var unavailableDates; function unavailable(date) { dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear(); if ($.inArray(dmy, unavailableDates) == -1) { return [true, ""]; } else { return [false, "", "Unavailable"]; } } $(document).ready(function() { $("#datepicker").datepicker({ dateFormat: 'yy-mm-dd', beforeShowDay: unavailable, minDate: 0, firstDay: 1, // rows starts on Monday changeMonth: true, changeYear: true, showOtherMonths: true, selectOtherMonths: true, altField: '#date_due', altFormat: 'yy-mm-dd' }); $('#datepicker').focus(function(){ //alert($('#name').html()); $.ajax({ url: 'getDates.php', data: "artist_id="+$('#name').html(), dataType: 'json', success: function(data) { alert(data) } }); }) }); Everything works fine. Using the "getDates.php" I retrieved the dates and pass them through the function. But how can I pass the data (after success: function) to the unavailable dates above? I have the dates from database but I don't know how to link them with the array "unavailableDates" (line 1) in order to show unavailable dates in datePicker.
  13. Hello, I am trying to create an array where by the items listed are nested with the names and the array spat out is easy to use when I am creating an ajax function with data from it all. Below is an idea of what I need to do: # This is where I am grabbing the data from the instagram class $data_url[] = $data->images->standard_resolution->url; $data_link[] = $data->link; $data_id[] = $data->getId(); $data_likes[] = $data->likes->count; {["images":[ ["data_url":[ ["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg"] ], ["data_link":[ ["http:\/\/instagram.com\/p\/cq2pjLMNNE\/"] ], ["data_id": [516465457066201924_288233123] ], ["data_likes": [18] ] ] ] } In my current ajax.php page, I am creating a place where data can be captured and I can use it to get the images and place them into a page. Here is what I have got so far: $instagram = new Instagram\Instagram; $instagram->setAccessToken($_SESSION['instagram_access_token']); $token = $_SESSION['instagram_access_token']; //$clientID = $_SESSION['client_id']; $current_user = $instagram->getCurrentUser(); $tag = $instagram->getTag('folkclothing'); $media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null); /* $params = isset( $_GET['max_tag_id'] ) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null; */ /* $media = $tag->getMedia($params); */ /* $next_page = $media->getNext(); */ /* // Receive new data $imageMedia = $instagram->pagination($media); */ // Collect everything for json output $images = array(); $data_link = array(); $data_id = array(); $data_likes = array(); foreach ($media as $data) { $images[] = array($data_url[] = $data->images->standard_resolution->url,$data_link[] = $data->link, $data_id[] = $data->getId(), $data_likes[] = $data->likes->count); } echo json_encode(array( 'next_id' => $media->getNextMaxTagId(), 'images' => $images )); Below is what my /ajax/ url gives me: {"next_id":"1374887530845","images":[["http:\/\/distilleryimage4.s3.amazonaws.com\/f8e5e2fafe8811e2a42922000a9e51c4_7.jpg","http:\/\/instagram.com\/p\/cq2pjLMNNE\/","516465457066201924_288233123",18],["http:\/\/distilleryimage10.s3.amazonaws.com\/46f790e0fdaf11e29de622000ae90e7b_7.jpg","http:\/\/instagram.com\/p\/coEUD0MyGO\/","515681128006492558_197168271",23],["http:\/\/distilleryimage6.s3.amazonaws.com\/7e510fa6fcee11e29a4b22000a1fb593_7.jpg","http:\/\/instagram.com\/p\/clmYo1AgU6\/","514986551277651258_20025128",25],["http:\/\/distilleryimage0.s3.amazonaws.com\/4f41be96fc3411e2829822000a9f1487_7.jpg","http:\/\/instagram.com\/p\/cjN3PipYkE\/","514315753313634564_190097401",10],["http:\/\/distilleryimage0.s3.amazonaws.com\/bcc8d83cfb9911e2921e22000aa81fd0_7.jpg","http:\/\/instagram.com\/p\/chPPNdGDhI\/","513758848433535048_6206549",13],["http:\/\/distilleryimage2.s3.amazonaws.com\/ef97af2efb5611e2b16122000a1f9e61_7.jpg","http:\/\/instagram.com\/p\/cgYg4ljpby\/","513518170419402482_52465932",1],["http:\/\/distilleryimage5.s3.amazonaws.com\/8e7bbf04fa9e11e2aea022000a9d0ee7_7.jpg","http:\/\/instagram.com\/p\/ceBeGXNpA9\/","512853874029531197_20203491",2],["http:\/\/distilleryimage4.s3.amazonaws.com\/96dc4444f9f811e2b88d22000a1fd1dd_7.jpg","http:\/\/instagram.com\/p\/cb5gooAgW4\/","512255913931965880_20025128",6],["http:\/\/distilleryimage11.s3.amazonaws.com\/6b80e884f9dc11e29b2522000a9f13d5_7.jpg","http:\/\/instagram.com\/p\/cbibv3JW9H\/","512154423034998599_430907394",20],["http:\/\/distilleryimage7.s3.amazonaws.com\/64f82bd6f95411e2a73522000a1faf50_7.jpg","http:\/\/instagram.com\/p\/cZzAF8syFb\/","511664339442409819_197168271",16],["http:\/\/distilleryimage10.s3.amazonaws.com\/b54645f4f93711e283e622000a1fb86d_7.jpg","http:\/\/instagram.com\/p\/cZbgGrlSzW\/","511560986135964886_187431354",17],["http:\/\/distilleryimage8.s3.amazonaws.com\/a9fc18a2f87111e29c8b22000a9f18f4_7.jpg","http:\/\/instagram.com\/p\/cW5Q5CBrlw\/","510847457153169776_378485429",6],["http:\/\/distilleryimage0.s3.amazonaws.com\/55b6269cf86311e2b5f422000a1f9a34_7.jpg","http:\/\/instagram.com\/p\/cWthoKit5E\/","510795830715407940_203990694",16],["http:\/\/distilleryimage9.s3.amazonaws.com\/bff691e2f82a11e2939b22000a1f9251_7.jpg","http:\/\/instagram.com\/p\/cV_K8mBu9R\/","510591961963884369_256035442",12],["http:\/\/distilleryimage4.s3.amazonaws.com\/5ef4c3c0f73811e2890322000a9e48f1_7.jpg","http:\/\/instagram.com\/p\/cS4nTwwE_U\/","509718699729506260_37194114",34],["http:\/\/distilleryimage8.s3.amazonaws.com\/a1b5f0acf6cb11e2957722000a1f9a39_7.jpg","http:\/\/instagram.com\/p\/cRfiPgmAWQ\/","509326925426591120_453101536",11],["http:\/\/distilleryimage6.s3.amazonaws.com\/4bf62240f68511e29aee22000a9f38e6_7.jpg","http:\/\/instagram.com\/p\/cQl6qiBzdu\/","509073517011482478_5670460",223],["http:\/\/distilleryimage1.s3.amazonaws.com\/d23848d6f61e11e2807c22000a9e06c7_7.jpg","http:\/\/instagram.com\/p\/cPR9_otpGt\/","508704309923713453_20203491",6]]} Can anyone guide me into the best way I can do this so it gives me an array from my ajax.php so I can grab the data and place it into my page better? I have tried numerous techniques but they have not worked at all. Thanks, Mark
  14. I have a multidimensional array like so. Array ( [0] => Array ( [0] => Yolo County Sheriff's Home 2008faroo [1] => http://www.yolosheriffs.com/ [2] => 86 ) [1] => Array ( [0] => Fremont, Yolo County, California - Wikipedia, the free encyclopediafaroo [1] => http://en.wikipedia.org/wiki/Fremont,_Yo… [2] => 11 ) [2] => Array ( [0] => The Lonely Island - YOLO (feat. Adam Levine & Kendrick Lamar) - YouTubefaroo [1] => http://www.youtube.com/watch?feature=pla… [2] => 45 ) What i need to do is find duplicate urls in this array, merge them together and combine the score found at [2]. I have scoured the php manual but I can't seem to find a way to merge the duplicate urls and then add the scores to the remaining url. Would it make it any easier to have it in the format Array ( [0] => Array ( [0] => Yolo County Sheriff's Home 2008faroo, array([0] => http://www.yolosheriffs.com/ ,[1] => 0) ) ?? All suggestions appreciated.I have looked at the manual but i don't have the knowledge at this stage to use the array functions in conjunction with foreach loops to achieve what i need.I
  15. I have a form which has multi-value select fields (Bootstrap) in which I can use to submit an array of data to the database. Now, the issue is I am having trouble retrieving that array with json_decode(). The issue is my array format for returning values: <?php echo json_decode( $this->prog[0]['schoolKey']) ); ?> When echoing out the above, I get the follow error message: "stripslashes() expects parameter 1 to be string, array given in ..." I know there is a easy solution, but I've been working 12 hours long and I can barely see straight. Any help with this is greatly appreciated.
  16. This is my script: I'm trying to save the contents of a database to json I've getting the database contents to echo out but can get it encoded into json. How can I do this or what am I doing wrong here? <?php echo '<link rel="stylesheet" href="css/styles.css" />'; // Create connection //$connection = mysqli_connect("localhost","root","","finalprojectapp"); //Localhost Connection //Check Connection if(mysqli_connect_errno($connection)){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); }else{ echo "Success, Connection Achieved"; } $result = mysqli_query($connection,"SELECT * FROM member"); while($row = mysqli_fetch_array($result)) { echo "<br/><br/>ID: <p>" . $row['id'] . "</p> Phone Number: <p>" . $row["phoneNumber"] . "</p> First Name: <p>" . $row["firstName"] . "</p> Last Name: <p>" . $row["lastName"] . "</p> Profile Picture: <p>" . $row["profilePicture"] . "</p> Photo: <p>" . $row["photo"] . "</p> Video: <p>" . $row["video"] . "</p> Text: <p>" . $row["text"] . "</p> Call: <p>" . $row["call"] . "</p> Activity: <p>" . $row["activity"] . "</p> Latitude: <p>" . $row["latitude"] . "</p> Longitude: <p>" . $row ["longitude"] . "</p> Date: <p>" . $row["date"] . "</p> Time: <p>" . $row["time"] . "</p><br/>"; } $a = array($row["id"],$row['phoneNumber'],$row['firstName'], "\xc3\xa9"); echo "Normal: ", json_encode($a), ""; mysqli_close($connection);
  17. I am using php to connect to my psql database and have some initial code to connect to a database, access a table and set a column to an array etc. I, however, have been struggling to get my data into a desired format that my code is already running on. My input is in Json hierarchical data form, as following. function getData() { return { "name": "data", "children": [ { "name": "America", "children": [ { "name": "MA", "children": [ {"name": "Westborough", "order": 30}, {"name": "Southborough", "order":20} ] }, { "name": "NH", "children": [ {"name": "Nashua", "order": 12} ] }, { "name": "CA", "children": [ {"name": "SanFransico", "order": 17} ] } ] } ] }; This is the code I currently have using php: <?php // attempt a connection $dbh = pg_connect("host=localhost dbname=sample user=postgres"); if (!$dbh) { die("Error in connection: " . pg_last_error()); } // execute query $sql = "SELECT * FROM dataset"; $result = pg_query($dbh, $sql); if (!$result) { die("Error in SQL query: " . pg_last_error()); } //Sets the column at 1 to an array $arr = pg_fetch_all_columns($result, 1); // free memory pg_free_result($result); // close connection pg_close($dbh); ?> This is the format of the database table Thanks in advance
  18. Guest

    PHP, Curl, and JSON

    Hey all. I've been playing with curl via the PHP command line, and I came up with this little curl based API interface to display the current BTC price from mtgox.com via the API. I've tried dumping the returned JSON'ized curl information into a string, and I've tried to query it, but so far no luck. I've used this script before for the Github API and it worked just fine. I've come to the conclusion it's because of the way that the JSON arrays are structured. Any help would be appreciated: <?php $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); curl_setopt($c, CURLOPT_URL, 'http://data.mtgox.com/api/2/BTCUSD/money/ticker'); $content = curl_exec($c); curl_close($c); $api = json_decode($content); return $api->avg; ?> The above code, when run with php -f btc.php returns an error: PHP Notice: Undefined property: stdClass::$avg in btc.php on line 12 Which makes me believe that my return: return $api->avg; is incorrect. So, I rechecked the API and the return path seems to be: Object->data->avg; So, I restructured my code to test to see if something like this would work: return $api->data->avg; OR return $api->data['avg']; And I receive a non-object error: PHP Notice: Trying to get property of non-object in btc.php on line 13 I was able to accomplish something very similar with Ruby and elinks: #!/bin/bash elinks -dump https://www.bitstamp.net/api/ticker/ > /tmp/btc.json cat /tmp/btc.json | ruby -e "require 'rubygems'; require 'json'; puts JSON[sTDIN.read]['ask'];" however, this is a script that I'd like to take with me (just so I can check on the BTC price on the go without a web browser), and not all of my terminals have Ruby; also elinks -dump is pretty slow compared to curl and PHP. Any ideas how I can access and return the current price within the JSON array?
  19. Hi I am trying to replicate this JSON post from online any ideas where I'm going wrong <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <title>TEST JSON</title> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script language="javascript" type="text/javascript"> j$(document).ready(function () { j$("#doVote").click(function () { var girlId = 'ctl00_Body_VotingPanel_hidGirlID' var searchString = 'ctl00_Body_VotingPanel_hidSearchString' if (j$("#" + girlId + "").val() == "") { girlId = 0; } else { girlId = j$("#" + girlId + "").val(); } var x = j$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://www.fhm.com/site/pages/girls/100sexiest2010/VotePopup.aspx/InsertVotee", data: "{girlId:" + girlId + ",girlName:'" + escape(j$("#" + searchString + "").val()) + "', shareType:3}", dataType: "json", error: function (xhr, status, error) { //j$("#voteError").show("slow"); //alert(xhr.statusText); //alert(error); }, success: function (voteid) { j$("#hidVoteId").val(voteid); j$(".coverflowContainer").animate({ left: '-=631px' }, 500); displayCompetitionBox(); } }); }); }); </script> </head> <body> <input type="hidden" value="1124" id="ctl00_Body_VotingPanel_hidGirlID" name="ctl00$Body$VotingPanel$hidGirlID"> <input type="hidden" id="ctl00_Body_VotingPanel_hidSearchString" name="ctl00$Body$VotingPanel$hidSearchString"> <a id="doVote" class="voteButton">Vote Now</a> </body> </html>
  20. I've got this use this ajax and json to pass the value of a table to server side PHP: $.ajax({ type: "POST", url: "json1.php", dataType: 'html', data: { json_1 : JSON.stringify(newArray), json_2 : JSON.stringify(newArray1) ,'key' : fileKey}, success: function(response){ $('#output').html(response); } }); on the server side I have no problem, but returning the value I've got this error Catchable fatal error: Object of class PHPExcel_Writer_Excel2007 could not be converted to string from blah blah blah I can't figure out what is the problem. Maybe its the JSON cause its converting the html element to JSON, but I already decode it on the server side $jsonData1 = json_decode($jsonData_1); $jsonData2 = json_decode($jsonData_2);
  21. Can anyone give me an idea on how I will count the table column and table row and get the id, attribute and the content of a each cell (the cell is contenteditable). What tools i have to use. e.g. <table id='sheet'> <tbody> <tr> <td id='1A' rowspan=2>Rowspan 2</td> <td id='1B'>22222</td> <td id='1C'>33333</td> </tr> <tr> <td id='2B' colspan='2'> Colspan2</td> </tr> <tr> <td id='3A' style='color:red'>Whaterver</td> <td id='3B' style='font-weight:bold'>Askyourmother</td> <td id='3C'>sigh</td> </tr> </tbody> </table> I'm using PHP and Jquery(Javascript). Thanks. .
  22. My brain is currently at it's threshold for processing this sort of thing on it's own, and I've been circling this challenge for hours with no success. Is there a way to take a JSON file (http://us.battle.net/auction-data/6de1a23eb7316db413a62771c8f16b93/auctions.json) And turn it into something I can use with PHP to reorganize and display the data in a way that makes sense? IE: Realm - Player Name - Item ID - Quantity - Bid - Buyout - Timeleft Preferrably in a CSV or MySQL DB so I ca simply foreach() the entire thing I apologise if I am not making a whole lot of sense, I am just at my wit's end.
  23. i am trying to load the current users images from instagrams api. i got there user id and other things but i cant seem to get the recent media that they posted ... here is the codes im using protected $_endpointUrls = array( 'authorize' => 'https://api.instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=%s', 'access_token' => 'https://api.instagram.com/oauth/access_token', 'user' => 'https://api.instagram.com/v1/users/%d/?access_token=%s', 'user_feed' => 'https://api.instagram.com/v1/users/self/feed?%s', 'user_recent' => 'https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s&max_id=%s&min_id=%s&max_timestamp=%s&min_timestamp=%s',); public function getUserRecent($id, $maxId = '', $minId = '', $maxTimestamp = '', $minTimestamp = '') { $endpointUrl = sprintf($this->_endpointUrls['user_recent'], $id, $this->getAccessToken(), $maxId, $minId, $maxTimestamp, $minTimestamp); $this->_initHttpClient($endpointUrl); return $this->_getHttpClientResponse(); } this is where i call upon those two to get the users photos but it wont display them <? $userphotos = $instagram-> getUserRecent($_SESSION['InstagramAccessToken']); $photos = json_decode($userphotos, true); ?> <?= $photos['data']['user']['user_recent'] ?>
  24. I am not able to successfully pass a JSON object as a parameter, i get an uncaught referenceError..any ideas? $.getJSON('./getMe.php', function(data){ $.each(data, function(key, pack){ var id = key.toLowerCase().replace(" ", "_"); $('#breadcrumbs').append(" <span id='" + id + " 'onclick='DoSomething(id, pack);'>" + key + "</span> "); }); $('#breadcrumbs').append('</br></br>'); }) .success(function(){ $('#loader').hide(); }); function DoSomething(id, pack){ $.each(pack, function(stage, items){ alert(stage); }); $('#packages').html('→ ' + id); }
  25. So basically want to have a search box and I want users to type in a name and then hit search. It then needs to search through multiple JSON files(11,480) to be precise. I want it to find the name inside the JSON and then pull other information from that JSON file. ATM I only have it where you put in the json file and then it reads the data. The code I currently have is; <?php $string = file_get_contents("2.json"); $json_a=json_decode($string,true); echo "First Name: ", $json_a['Item'][FirstName]; echo "<br>Surname: ", $json_a['Item'][LastName]; echo "<Br>Height: ", $json_a['Item'][Height], "cm"; echo "<br>Rating: ", $json_a['Item'][Rating], " OVRL"; echo "<br>Pace: ", $json_a['Item'][Attribute1]; echo "<br>Shooting: ", $json_a['Item'][Attribute2]; echo "<br>Passing: ", $json_a['Item'][Attribute3]; echo "<br>Dribbling: ", $json_a['Item'][Attribute4]; echo "<br>Defending: ", $json_a['Item'][Attribute5]; echo "<br>Heading: ", $json_a['Item'][Attribute6]; ?> 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.