Jump to content

Search the Community

Showing results for tags 'json'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • 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


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

  1. 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){ ...
  2. 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
  3. 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
  4. 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!"); } ?>
  5. 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() .'}}'; } ?>
  6. 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.
  7. 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.
  8. 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
  9. 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
  10. 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.
  11. 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);
  12. 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
  13. 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?
  14. 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>
  15. 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);
  16. 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. .
  17. 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.
  18. 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'] ?>
  19. 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); }
  20. 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
  21. I have a company that needs php tweaking. (My previous programmer couldn't be found anymore) The client e-mailed me this "Basically what we need is for you to provide us with an http rest API where we will provide the tracking code and in return you will return to us a JSON object with the status of the delivery As an example: TRACKING CODE: ABCDEFGHIJ URL: http://mydomain.com/track.php?code=ABCDEFGHIJ METHOD: GET RESPONSE: {"status":2} where 2 is the code for the status shipment which is defined by 1 - GOOD 2 - BETTER 3 - BEST" How and where do I place this? What's "HTTP REST API" and "return to us a JSON object" It's all gibberish to me! Some web guru answer me pls? Thanks in advance!
  • 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.