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. Can someone please help me? i cant quite figure out how to parse out the following json data: {"data":[{"id":2464,"vehiclemodel_id":969,"vehicleyear_id":39,"created_at":"2016-10-10 14:51:02","updated_at":"2016-10-10 14:51:02","attributevalues":{"data":[]},"items":{"data":[{"id":389,"brand_id":406,"country_id":227,"product_id":6,"sku":"015-01003","name":"MULTIRATE FORK SPRINGS 41MM","list_price":"126.95","standard_dealer_price":"88.99","supplier_product_id":"FS-1028","length":24.5,"width":4.7,"height":1.9,"weight":3.42,"upc":null,"superseded_sku":null,"status_id":"STK","status":"STK","unit_of_measurement_id":null,"has_map_policy":false,"sort":0,"created_at":"2016-06-17 20:47:51","updated_at":"2022-01-03 17:39:04","published_at":"2016-06-17 20:47:51","images":{"data":[{"id":94477,"domain":"cdn.wpsstatic.com\/","path":"images\/","filename":"88ff-5b02f15f8c0b7.jpg","alt":null,"mime":"image\/jpeg","width":5419,"height":3473,"size":6496067,"signature":"2f99154396b9412e1a0db1c10f29fdf1fc989f9db8236efdb28d52341a445405","created_at":"2018-05-21 16:18:46","updated_at":"2018-05-21 16:18:46"}]}},{"id":394,"brand_id":406,"country_id":227,"product_id":263235,"sku":"015-01012","name":"LOWERING FORK SPRINGS 41MM","list_price":"139.95","standard_dealer_price":"98.99","supplier_product_id":"LK-2011","length":24.5,"width":4.5,"height":1.7,"weight":3.43,"upc":null,"superseded_sku":null,"status_id":"STK","status":"STK","unit_of_measurement_id":null,"has_map_policy":false,"sort":0,"created_at":"2016-06-17 20:47:51","updated_at":"2022-01-03 17:39:05","published_at":"2016-06-17 20:47:51","images":{"data":[{"id":174,"domain":"cdn.wpsstatic.com\/","path":"images\/","filename":"becb-572a4ec444772.jpg","alt":null,"mime":"image\/jpeg","width":1000,"height":447,"size":138779,"signature":"dc570b1218a024f1acf9dd4b39fc6e7ea2a12d64fae46622e2a25d85e31d8d76","created_at":"2016-05-04 19:34:28","updated_at":"2017-02-23 18:01:01"}]}},{"id":634992,"brand_id":434,"country_id":227,"product_id":185661,"sku":"810-0607","name":"BRAKE PEDAL COVER TOURING BAD AXE BLACK","list_price":"99.00","standard_dealer_price":"69.30","supplier_product_id":"BAX-340-BLK","length":7,"width":5,"height":1,"weight":1,"upc":null,"superseded_sku":null,"status_id":"NEW","status":"NEW","unit_of_measurement_id":12,"has_map_policy":true,"sort":0,"created_at":"2022-04-13 07:53:11","updated_at":"2022-05-16 07:31:54","published_at":"2022-05-16 07:31:54","images":{"data":[]}}]},"vehiclemodel":{"data":{"id":969,"vehiclemake_id":22,"db2_key":"193","name":"FLSTF Softail Fat Boy","created_at":"2016-10-10 14:47:50","updated_at":"2018-04-11 17:43:23","vehiclemake":{"data":{"id":22,"db2_key":"HARLEY","name":"Harley-Davidson","created_at":"2016-10-10 14:47:14","updated_at":"2021-12-22 17:44:31"}}}},"vehicleyear":{"data":{"id":39,"name":1993,"created_at":"2016-10-10 14:50:07","updated_at":"2016-10-10 14:50:07"}}}],"meta":{"cursor":{"current":"61poYD9eaDkR","prev":null,"next":null,"count":1}}} here is where it is also layed out differently: { "data": [ { "id": 2464, "vehiclemodel_id": 969, "vehicleyear_id": 39, "created_at": "2016-10-10 14:51:02", "updated_at": "2016-10-10 14:51:02", "attributevalues": { "data": [] }, "items": { "data": [ { "id": 389, "brand_id": 406, "country_id": 227, "product_id": 6, "sku": "015-01003", "name": "MULTIRATE FORK SPRINGS 41MM", "list_price": "126.95", "standard_dealer_price": "88.99", "supplier_product_id": "FS-1028", "length": 24.5, "width": 4.7, "height": 1.9, "weight": 3.42, "upc": null, "superseded_sku": null, "status_id": "STK", "status": "STK", "unit_of_measurement_id": null, "has_map_policy": false, "sort": 0, "created_at": "2016-06-17 20:47:51", "updated_at": "2022-01-03 17:39:04", "published_at": "2016-06-17 20:47:51", "images": { "data": [ { "id": 94477, "domain": "cdn.wpsstatic.com/", "path": "images/", "filename": "88ff-5b02f15f8c0b7.jpg", "alt": null, "mime": "image/jpeg", "width": 5419, "height": 3473, "size": 6496067, "signature": "2f99154396b9412e1a0db1c10f29fdf1fc989f9db8236efdb28d52341a445405", "created_at": "2018-05-21 16:18:46", "updated_at": "2018-05-21 16:18:46" } ] } }, { "id": 394, "brand_id": 406, "country_id": 227, "product_id": 263235, "sku": "015-01012", "name": "LOWERING FORK SPRINGS 41MM", "list_price": "139.95", "standard_dealer_price": "98.99", "supplier_product_id": "LK-2011", "length": 24.5, "width": 4.5, "height": 1.7, "weight": 3.43, "upc": null, "superseded_sku": null, "status_id": "STK", "status": "STK", "unit_of_measurement_id": null, "has_map_policy": false, "sort": 0, "created_at": "2016-06-17 20:47:51", "updated_at": "2022-01-03 17:39:05", "published_at": "2016-06-17 20:47:51", "images": { "data": [ { "id": 174, "domain": "cdn.wpsstatic.com/", "path": "images/", "filename": "becb-572a4ec444772.jpg", "alt": null, "mime": "image/jpeg", "width": 1000, "height": 447, "size": 138779, "signature": "dc570b1218a024f1acf9dd4b39fc6e7ea2a12d64fae46622e2a25d85e31d8d76", "created_at": "2016-05-04 19:34:28", "updated_at": "2017-02-23 18:01:01" } ] } }, { "id": 634992, "brand_id": 434, "country_id": 227, "product_id": 185661, "sku": "810-0607", "name": "BRAKE PEDAL COVER TOURING BAD AXE BLACK", "list_price": "99.00", "standard_dealer_price": "69.30", "supplier_product_id": "BAX-340-BLK", "length": 7, "width": 5, "height": 1, "weight": 1, "upc": null, "superseded_sku": null, "status_id": "NEW", "status": "NEW", "unit_of_measurement_id": 12, "has_map_policy": true, "sort": 0, "created_at": "2022-04-13 07:53:11", "updated_at": "2022-05-16 07:31:54", "published_at": "2022-05-16 07:31:54", "images": { "data": [] } } ] }, "vehiclemodel": { "data": { "id": 969, "vehiclemake_id": 22, "db2_key": "193", "name": "FLSTF Softail Fat Boy", "created_at": "2016-10-10 14:47:50", "updated_at": "2018-04-11 17:43:23", "vehiclemake": { "data": { "id": 22, "db2_key": "HARLEY", "name": "Harley-Davidson", "created_at": "2016-10-10 14:47:14", "updated_at": "2021-12-22 17:44:31" } } } }, "vehicleyear": { "data": { "id": 39, "name": 1993, "created_at": "2016-10-10 14:50:07", "updated_at": "2016-10-10 14:50:07" } } } ], "meta": { "cursor": { "current": "61poYD9eaDkR", "prev": null, "next": null, "count": 1 } } } i can get the id 2464 but i cant get data under items -> data -> id (389) , or images data -> filename or list_price ect.. please help
  2. I have here a select query where in I have to get the $den_name and $currDate from a js variable. $disData="SELECT bDate.* FROM (SELECT bDentist.* FROM ( SELECT bBranch.*,concat(px_fname,' ', px_lname) as px_name, concat(px_contact,' / ', px_contact2) as px_connum FROM appointments bBranch WHERE bBranch.brnch_id = '$id') AS bDentist WHERE bDentist.den_name = '$dentistName') AS bDate WHERE bDate.s_date = '$currDate'"; The reason for doing this is so that I can output the records when I clicked a specific date and dentist #1 that matches their values. I tried using ajax here is my code for trying to get the dentist's name // JS Var currDen to PHP Var const den1 = document.querySelector('.D1'); const den2 = document.querySelector('.D2'); const den3 = document.querySelector('.D3'); let currDen = ''; // if 'active' exists if( den1.classList.contains('active')) { currDen = document.getElementById("D1").innerHTML; }else if (den2.classList.contains('active')){ currDen = document.getElementById("D2").innerHTML; }else if (den3.classList.contains('active')){ currDen = document.getElementById("D3").innerHTML; }else{ currDen = '땡!'; }; console.log(currDen); const xhrDen = new XMLHttpRequest(); jsonStr = JSON.stringify(currDen); console.log (jsonStr); xhrDen.open("POST" , "clickedD.php"); xhrDen.setRequestHeader("Content-type" , "application/json"); xhrDen.send(jsonStr); }); }); this is the clickedD.php where I post it <?php $requestPayload= file_get_contents("php://input"); var_dump($requestPayload); $dentistName = json_decode($requestPayload,true); var_dump($dentistName); echo $dentistName; and in does return this to the network dev tool I also tried checking it if its empty with this if (empty($requestPayload)) { echo "Variable is empty.<br>"; } else { echo $requestPayload; } if (empty($dentistName)) { echo "Variable is empty.<br>"; } and this is what it output what is wrong with my code ? please help me out
  3. I'm having a bit of trouble understanding why json_decode() is returning a null value, hoping someone has the time, will and energy to break it down for me. I've looked it up from various sources and don't get why it's not working. There's the following -> <?php public function hasPermission($key) { $group = $this->_db->get("groups", array("id", "=", $this->data()->group)); if($group->count()) { $permissions = $group->first()->permissions; echo gettype($permissions); echo $permissions; } } This returns $permissions as a string -> But when I do this -> <?php public function hasPermission($key) { $group = $this->_db->get("groups", array("id", "=", $this->data()->group)); if($group->count()) { $permissions = json_decode($group->first()->permissions, true); echo gettype($permissions); } } permissions comes back as a null type. I've been reading about json_decode() and it requires a json string in UTF-8 encoded. Which my data is (or seems to me to be). Could someone point out my error, please?! Thank you
  4. I've been working on JSON and have found a way to send variables from the PHP to the JavaScript using AJAX and no JQuery. For an ecommerce site does it make more sense to send the variables : description, title, cost, etc. to the JavaScript page, or would it make more sense to echo the html on the PHP page? The idea, right now, is a product page for editing and deleting product. Thanks, Josh
  5. I have my data array which i converted to json by splitting the keys using for each loop. Data: $data = Array ( [table6-ios-camt] => [table6-ios-iamt] => [table6-ios-samt] => [table6-ios-type] => [table6-isd-camt] => 0 [table6-isd-iamt] => 0 [table6-isd-samt] => 0 [table6-isd-type] => [table6-ios-csamt] => [table6-isd-csamt] => 0 [table6-other-camt] => [table6-other-iamt] => [table6-other-samt] => [table6-other-type] => [table6-tran1-camt] => 0 [table6-tran1-iamt] => [table6-tran1-samt] => 0 [table6-tran1-type] => [table6-tran2-camt] => 0 [table6-tran2-iamt] => [table6-tran2-samt] => 0 [table6-tran2-type] => [table6-itc_3b-csamt] => 0 [table6-dump_iog-camt] => [table6-dump_iog-iamt] => [table6-dump_iog-samt] => [table6-dump_iog-type] => [table6-dump_oth-camt] => 4386.09 [table6-dump_oth-iamt] => [table6-dump_oth-samt] => 4386.09 [table6-dump_oth-type] => [table6-itc_clmd-camt] => [table6-itc_clmd-iamt] => [table6-itc_clmd-samt] => [table6-itc_clmd-type] => [table6-total_10-camt] => 4386.09 [table6-total_10-iamt] => 0 [table6-total_10-samt] => 4386.09 [table6-total_10-type] => [table6-total_11-type] => [table6-total_8-csamt] => 0 [table6-total_9-csamt] => 0 [table6-dump_iog-csamt] => [table6-dump_isrc-camt] => [table6-dump_isrc-iamt] => [table6-dump_isrc-samt] => [table6-dump_isrc-type] => [table6-dump_oth-csamt] => [table6-iog_goods-camt] => [table6-iog_goods-iamt] => [table6-iog_goods-samt] => [table6-iog_goods-type] => Capital Goods [table6-itc_clmd-csamt] => [table6-total_10-csamt] => 0 [table6-dump_isrc-csamt] => [table6-iog_goods-csamt] => [table6-iog_inputs-camt] => [table6-iog_inputs-iamt] => [table6-iog_inputs-samt] => [table6-iog_inputs-type] => Input Services [table6-iog_inputs-csamt] => [table6-iog_services-camt] => [table6-iog_services-iamt] => [table6-iog_services-samt] => [table6-iog_services-type] => Input Services [table6-supp_non_rchrg_goods-camt] => [table6-supp_non_rchrg_goods-iamt] => [table6-supp_non_rchrg_goods-samt] => [table6-supp_non_rchrg_goods-type] => Capital Goods [table6-supp_rchrg_reg_goods-camt] => [table6-supp_rchrg_reg_goods-iamt] => [table6-supp_rchrg_reg_goods-samt] => [table6-supp_rchrg_reg_goods-type] => Capital Goods [table6-supp_non_rchrg_goods-csamt] => [table6-supp_non_rchrg_inputs-camt] => 4386.09 [table6-supp_non_rchrg_inputs-iamt] => [table6-supp_non_rchrg_inputs-samt] => 4386.09 [table6-supp_non_rchrg_inputs-type] => Inputs [table6-supp_rchrg_reg_goods-csamt] => [table6-supp_rchrg_reg_inputs-camt] => [table6-supp_rchrg_reg_inputs-iamt] => [table6-supp_rchrg_reg_inputs-samt] => [table6-supp_rchrg_reg_inputs-type] => Input Services [table6-supp_non_rchrg_inputs-csamt] => [table6-supp_rchrg_reg_inputs-csamt] => [table6-supp_rchrg_unreg_goods-camt] => [table6-supp_rchrg_unreg_goods-iamt] => [table6-supp_rchrg_unreg_goods-samt] => [table6-supp_rchrg_unreg_goods-type] => Capital Goods [table6-supp_non_rchrg_services-camt] => [table6-supp_non_rchrg_services-iamt] => [table6-supp_non_rchrg_services-samt] => [table6-supp_non_rchrg_services-type] => Input Services [table6-supp_rchrg_reg_services-camt] => [table6-supp_rchrg_reg_services-iamt] => [table6-supp_rchrg_reg_services-samt] => [table6-supp_rchrg_reg_services-type] => Input Services [table6-supp_rchrg_unreg_goods-csamt] => [table6-supp_rchrg_unreg_inputs-camt] => [table6-supp_rchrg_unreg_inputs-iamt] => [table6-supp_rchrg_unreg_inputs-samt] => [table6-supp_rchrg_unreg_inputs-type] => Input Services [table6-supp_non_rchrg_services-csamt] => [table6-supp_rchrg_reg_services-csamt] => [table6-supp_rchrg_unreg_inputs-csamt] => [table6-supp_rchrg_unreg_services-camt] => [table6-supp_rchrg_unreg_services-iamt] => [table6-supp_rchrg_unreg_services-samt] => [table6-supp_rchrg_unreg_services-type] => Input Services [table6-supp_rchrg_unreg_services-csamt] => ); json: { "table6":{ "ios":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "isd":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "other":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "tran1":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "tran2":{ "camt":0, "iamt":0, "samt":0, "csamt":0 }, "itc":{ "camt":0, "iamt":550, "samt":230, "csamt":680 }, "iog":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ], "supp_non_rchrg":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":4386.09, "samt":4386.09, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ], "supp_rchrg_reg":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ], "supp_rchrg_unreg":[ { "itc_typ":"cg", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"ip", "camt":0, "samt":0, "iamt":0, "csamt":0 }, { "itc_typ":"is", "camt":0, "samt":0, "iamt":0, "csamt":0 } ] } } The next thing i want to do is to unset the keys or entire inner objects of the json. Keeping in mind the following conditions: 1.If all the keys in the objects are 0 then the entire object will be removed (easy part). 2.If a key in the object has any value other than 0 , the object should not be removed and the key with "0" value should also be there. i've tried splitting value and using conditions to check for 0 or null values but the problem with that is it removes all keys that have 0 values thus failing condition 2 for the code. $vars = $data; $count = ""; $finalArray = array(); foreach ($vars as $keys => $values) { foreach ($values as $k => $v) { foreach ($v as $ke => $ve) { if ($keys == "table6") { $count = (array)$v; foreach ($count as $ck => $cv) { if ($cv != "0") { $flag = true; break; } } if($flag == false) { array_push($finalArray, $count); } } } } print_r($finalArray); die(); I expeced the output to contain the objects with key value pairs that does not contain 0 value but everything prints here.
  6. $outp = ""; while($rs = $result->fetch_array(MYSQLI_ASSOC)) { if ($outp != "") {$outp .= "";} $outp .= '{"Portrait":"' . $rs["Portrait"] . '",'; $outp .= '"First Name":"' . $rs["FName"] . '",'; $outp .= '"Last Name":"' . $rs["LName"] . '",'; $outp .= '"DOI":"'. $rs["DOI"] . '",'; $outp .= '"MOI":"'. $rs["MOI"] . '",'; $outp .= '"YOI":"'. $rs["YOI"] . '",'; $outp .= '"ID":"'. $rs["id"] . '"}'; } $outp ='{"records":['.$outp.']}'; Hi for the above PHP code the output looks like this JSON format { "records": [{ "Portrait": "image1.png", "First Name": "Dave", "Last Name": "Smith", "DOI": "20", "MOI": "0", "YOI": "2017", "ID": "1" } { "Portrait": "image2.png", "First Name": "Sally", "Last Name": "Jones", "DOI": "20", "MOI": "0", "YOI": "2009", "ID": "2" }] } and this doesn't validate because there should be comma in between records like this: { "records": [{ "Portrait": "image1.png", "First Name": "Dave", "Last Name": "Smith", "DOI": "20", "MOI": "0", "YOI": "2017", "ID": "1" }, { "Portrait": "image2.png", "First Name": "Sally", "Last Name": "Jones", "DOI": "20", "MOI": "0", "YOI": "2009", "ID": "2" }] } I am trying to figure out how to get a comma added between records without also adding it at the end, b/c that is invalid also. Any ideas?
  7. I have made an ajax call (using file activedirectory.php) to active directory to retrieve information such as name,thumbnail photo,mail etc. the ajax call is made on click of a name in a leaderboard ,to fetch only that person's info by matching the post['id']. The problem is that I am unable to retrieve any information and the console gives me an error saying : SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data the error type makes it clear that it is unable to pull any data whatsoever. .php file that has been used here :(activedirectory.php) -- <?php /** * Get a list of users from Active Directory. */ $ad_users = ''; $message = ''; $ldap_password = 'Qwerty@33xxxxxx'; $ldap_username = 'maxxxxxxxxxxxx'; $server = 'ldap://xxxxxxxxxx'; $domain = '@asia.xxxxxx.com'; $port = 389; $ldap_connection = ldap_connect($server, $port); if (FALSE === $ldap_connection){ // Uh-oh, something is wrong... } // We have to set this option for the version of Active Directory we are using. ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version'); ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search. if (TRUE === ldap_bind($ldap_connection, $ldap_username.$domain, $ldap_password)){ $base_dn = "OU=Employees,OU=Accounts,OU=xxxxx,DC=xxxxx,DC=xxxxxx,DC=com"; $kid = 'NonExistingAccount'; if (preg_match('#SAM_NAME_MATCHING_REGEX#', $_POST['id'])) { $kid = $_POST['id']; } $search_filter = "(&(objectCategory=person)(samaccountname={$kid}))"; $attributes = array(); $attributes[] = 'givenname'; $attributes[] = 'mail'; $attributes[] = 'samaccountname'; $attributes[] = 'sn'; $result = ldap_search($ldap_connection, $base_dn, $search_filter, $attributes); $maxPageSize = 1000; if (FALSE !== $result){ $entries = ldap_get_entries($ldap_connection, $result); for ($x=0; $x<$entries['count']; $x++){ if (!empty($entries[$x]['givenname'][0]) && !empty($entries[$x]['mail'][0]) && !empty($entries[$x]['samaccountname'][0]) && !empty($entries[$x]['sn'][0]) && 'Shop' !== $entries[$x]['sn'][0] && 'Account' !== $entries[$x]['sn'][0]){ $ad_users[strtoupper(trim($entries[$x]['samaccountname'][0]))] = array('email' => strtolower(trim($entries[$x]['mail'][0])),'first_name' => trim($entries[$x]['givenname'][0]),'last_name' => trim($entries[$x]['sn'][0])); } } } ldap_unbind($ldap_connection); // Clean up after ourselves. } $message .= "Retrieved ". count($ad_users) ." Active Directory users\n"; ?> the javascript that has been used here : $('.leaderboard li').on('click', function () { $.ajax({ url: "../popupData/activedirectory.php", // your script above a little adjusted type: "POST", data: {id:$(this).find('.parent-div').data('id')}, success: function(data){ console.log(data); data = JSON.parse(data); $('#popup').fadeIn(); //whatever you want to fetch ...... // etc .. }, error: function(){ alert('failed, possible script does not exist'); } }); });
  8. I'm trying to save some json data to an mysql table through php but I do have some issues I'm just stuck into the loop and the validation doesn't go like I want to. These are some dummy data of the json Object [entiteteTeReja] => Array ( [cmimeReja] => Array ( [0] => Array ( [KODNIVELCMIMI] => N1 [KODARTIKULLI] => BOBLT0009 [KODNJESIA1] => cope [MONEDHAKOD] => LEK [DTFILLIMIT] => 2015-01-01T00:00:00.000Z [DTMBARIMIT] => 9999-12-31T00:00:00.000Z [CMIMI] => 3450 [CMIMI2] => 3450 [KODNJESIA2] => cope [DTMODIFIKIM] => 2015-05-11T16:42:45.046Z [IDSTATUSDOK] => 1 [BRUTONETONIVELCMIMI] => 1 [NIVELCMIMIBAZE] => [KOHEFILLIMI] => 1900-01-01T00:00:00.000Z [KOHEMBARIMI] => 1900-01-01T23:59:59.000Z ) . . . . [834] => Array ( [KODNIVELCMIMI] => N2 [KODARTIKULLI] => BOBLT0009 [KODNJESIA1] => cope [MONEDHAKOD] => LEK [DTFILLIMIT] => 2015-01-01T00:00:00.000Z [DTMBARIMIT] => 9999-12-31T00:00:00.000Z [CMIMI] => 3450 [CMIMI2] => 3450 [KODNJESIA2] => cope [DTMODIFIKIM] => 2015-05-12T16:58:24.746Z [IDSTATUSDOK] => 1 [BRUTONETONIVELCMIMI] => 1 [NIVELCMIMIBAZE] => [KOHEFILLIMI] => 1900-01-01T00:00:00.000Z [KOHEMBARIMI] => 1900-01-01T23:59:59.000Z ) . . . . [834] => Array ( [KODNIVELCMIMI] => N3 [KODARTIKULLI] => BOBLT0009 [KODNJESIA1] => cope [MONEDHAKOD] => LEK [DTFILLIMIT] => 2015-01-01T00:00:00.000Z [DTMBARIMIT] => 9999-12-31T00:00:00.000Z [CMIMI] => 3450 [CMIMI2] => 3450 [KODNJESIA2] => cope [DTMODIFIKIM] => 2015-05-12T16:58:24.746Z [IDSTATUSDOK] => 1 [BRUTONETONIVELCMIMI] => 1 [NIVELCMIMIBAZE] => [KOHEFILLIMI] => 1900-01-01T00:00:00.000Z [KOHEMBARIMI] => 1900-01-01T23:59:59.000Z ) lso this is the Php Script that I tried so far, foreach($obj['entiteteTeReja']['cmimeReja'] as $key => $x){ $query = "SELECT COUNT(*) AS nr FROM cmimedatatable WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; $result = $mysqli->query($query); if( nr == 1){ if($x['KODNIVELCMIMI'] == 'N1'){ $query = "UPDATE cmimedatatable SET C1 = ".$x['CMIMI']." WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; } else if($x['KODNIVELCMIMI'] == 'N2'){ $query = "UPDATE cmimedatatable SET C2 = ".$x['CMIMI']." WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; } else if($x['KODNIVELCMIMI'] == 'N3'){ $query = "UPDATE cmimedatatable SET C3 = ".$x['CMIMI']." WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; } else if($x['KODNIVELCMIMI'] == 'N4'){ $query = "UPDATE cmimedatatable SET C4 = ".$x['CMIMI']." WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; } else if($x['KODNIVELCMIMI'] == 'N5'){ $query = "UPDATE cmimedatatable SET C5 = ".$x['CMIMI']." WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; } else if($x['KODNIVELCMIMI'] == 'N6'){ $query = "UPDATE cmimedatatable SET C6 = ".$x['CMIMI']." WHERE KODARTIKULLI = '".$x['KODARTIKULLI']."' "; } } else if ( nr == 0){ if($x['KODNIVELCMIMI'] == 'N1'){ $query = "INSERT INTO cmimedatatable(KODARTIKULLI, C1,C2, C3, C4, C5, C6) VALUES('".$x['KODARTIKULLI']."',".$x['CMIMI'].",0,0,0,0,0)"; } else if($x['KODNIVELCMIMI'] == 'N2'){ $query = "INSERT INTO cmimedatatable(KODARTIKULLI, C1,C2, C3, C4, C5, C6) VALUES('".$x['KODARTIKULLI']."',0,".$x['CMIMI'].",0,0,0,0)"; } else if($x['KODNIVELCMIMI'] == 'N3'){ $query = "INSERT INTO cmimedatatable(KODARTIKULLI, C1,C2, C3, C4, C5, C6) VALUES('".$x['KODARTIKULLI']."',0,0,".$x['CMIMI'].",0,0,0)"; } else if($x['KODNIVELCMIMI'] == 'N4'){ $query = "INSERT INTO cmimedatatable(KODARTIKULLI, C1,C2, C3, C4, C5, C6) VALUES('".$x['KODARTIKULLI']."',0,0,0,".$x['CMIMI'].",0,0)"; } else if($x['KODNIVELCMIMI'] == 'N5'){ $query = "INSERT INTO cmimedatatable(KODARTIKULLI, C1,C2, C3, C4, C5, C6) VALUES('".$x['KODARTIKULLI']."',0,0,0,0,".$x['CMIMI'].",0)"; } else if($x['KODNIVELCMIMI'] == 'N6'){ $query = "INSERT INTO cmimedatatable(KODARTIKULLI, C1,C2, C3, C4, C5, C6) VALUES('".$x['KODARTIKULLI']."',0,0,0,0,0,".$x['CMIMI'].")"; } } $mysqli->query($query); } And this is how the data are saved in my table,
  9. Hello I have several json files in one directory. i would like to merge them in to one. I did something like this <?php foreach (glob("../json/*.json") as $filename) { echo basename($filename) . "\n"; } $res1 = file_get_contents($filename); echo $res1; ?> But it echoes only the last (the first echo is to view all files which is not important here) Then I tried many versions of foreach inside foreach with no success. Like this: <?php foreach (glob("../json/*.json") as $filename) { foreach (file_get_contents($filename) as $a) { } } echo $a; ?> So I appreciate a little help here, thank you.
  10. webdevdea

    Json help

    at my link http://dandewebwonders.com/BBProject%204/index.php when you click on players you see the error.. this is what i need to do .. change data type from html to json, fix the controller error, and change it to parse the data.data object. case "listPlayers_Data" : $response = null; $results = array(); $players = new PlayersClass(); foreach ($players -> RetrieveAll() as $row) { $results[] = new PlayerListModel($row -> Id); } $response -> data = $results; echo json_encode($response); break; and a link to the project on github https://github.com/deannariddlespur/bb_Project/blob/master/Controllers/Controller.php
  11. Hello Mate, I would like to seek help... i have this json script which gets the names of the users from my database: $sql=mysql_query("SELECT firstname FROM tblusers WHERE usertype=1"); $u = array(); while($rs=mysql_fetch_array($sql)){ $u[] = $rs['firstname']; } print json_encode($u); And getting this to javascript function through ajax: function uList(){ $.ajax({ type: "POST", url: "techs.php", success: function(data) { console.log(data); return data; } }); } my console.log shows the correct format i want to get, but it doesn't display on my calendar page.... ["user1","user2","user3","user4","user5"]... im using this code to send data to my calendar script. users:uList, Any help is very much appreciated. Thank you
  12. hello mate, i need help on creating the json file with data are fetched from mysql database. here will be the result i want to get. { "freebusys":[ { "start":"2012-12-20T16:29:34.000+0000", "end":"2013-02-06T16:44:24.000+0000", "free":true } ], "events":[ { "start":"2013-01-04T03:57:06.000+0000", "end":"2013-02-18T03:57:06.000+0000", "id":2, "title":"A lesson" }, { "start":"2013-01-04T12:43:30.000+0000", "end":"2013-02-18T12:43:30.000+0000", "id":4, "title":"A lesson" } ] } i have a table named "schedules" on my database with the following fields, start, end, id, title, and free, all i need is to do php array "freebusys" and "events" then their values will be fetched from my database. how can i do this. please help. Thank you
  13. Hi Peeps So basically im creating a "customer page" i have 2 tabs, 1 is customer info which is the primary and the invoicing tab I have a date picker in the invoicing tab which im hoping will populate a table below. I tried having the form post to php but this resets the page which then goes to the customer info tab so im guessing this will have to be done with jquery and ajax. could someone please point me in the right direction to do this? here is the current page for better explanation: All help is greatly appreciated in advance Mooseh
  14. hi mate, i have this json output and i need this to be in php array how can i do this, events : [ {'id':1, 'start': new Date(year, month, day, 12), 'end': new Date(year, month, day, 13, 00), 'title': 'Lunch with Sarah', userId: [1, 2]}, {'id':2, 'start': new Date(year, month, day, 14), 'end': new Date(year, month, day, 14, 40), 'title': 'Team Meeting', userId: 0}, ], free: [ {'start': new Date(year, month, day-1, , 'end': new Date(year, month, day-1, 18), 'free': true, userId: [0,1,2,3]}, {'start': new Date(year, month, day, , 'end': new Date(year, month, day+0, 18), 'free': true, userId: [0,1,2,3]}, ] Thanks in advance
  15. Wondering Am I doing the correct thing. Im using qtip2 plug in to show something from another page content. I have 2 pages of php. aa.php <html> <head> <title>My site</title> <!-- CSS file --> <link type="text/css" rel="stylesheet" href="http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.css" /> </head> <body> <!-- jQuery FIRST i.e. before qTip (and all other scripts too usually) --> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <!-- Include either the minifed or production version, NOT both!! --> <script type="text/javascript" src="http://cdn.jsdelivr.net/qtip2/2.2.1/jquery.qtip.js"></script> <!-- Optional: imagesLoaded script to better support images inside your tooltips --> <script type="text/javascript" src="/path/to/jquery.imagesloaded.pkg.min.js"></script> <a href="#">Test</a> <script type="text/javascript"> $('a').qtip({ content: { text: function(event, api) { $.ajax({ url: 'aaCal.php', // URL to the JSON file dataType: 'json', // Tell it we're retrieving JSON }) .then(function(data) { /* Process the retrieved JSON object * Retrieve a specific attribute from our parsed * JSON string and set the tooltip content. */ var content = 'My name is ' + data.person.firstName; // Now we set the content manually (required!) api.set('content.text', content); }, function(xhr, status, error) { // Upon failure... set the tooltip content to the status and error value api.set('content.text', status + ': ' + error); }); return 'Loading...', // Set some initial loading text } } }); Another page aaCal.php $arr = array('person' =>array('firstname' => "Foo")); echo json_encode($arr); The output of aaCal.php is {"person":{"firstname":"Foo"}}. reference plug in guide: http://qtip2.com/guides
  16. Hi I try to show lists in random order. I have json that I decode to arrays and loop over it and show the result. Now I have teried to how it in a random order. but no result. tried allready several different ways.. here is something about: $json_results = json_decode($results,true); $groups = $json_results['response']['groups']; echo '<ul>'; shuffle($groups); foreach($groups as $group) It does continue to function, but with no randomizing order. just same as always..please help. Thanks
  17. I get funny result from my * echo $item['text']; * I do get the strings I intend to. Eg. I would like to have or sholud get the result: /Barrafina Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here. Matt Ta-Min/ But instead I get /Barrafina ee Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here. 5 5 E Eu uh h Matt Ta-Min / What did I do wrong? here is the code: If you have time and energy to look the JSON you will see from where eg.5 5 E Eu uh h.. comes. I appreciate any help. This is too strange for me. $json_results = json_decode($results,true); //var_dump($json_results); $items0 = $json_results['response']['groups']['0']['items']['0']; $items1 = $json_results['response']['groups']['0']['items']['0']['tips']; $items2 = $json_results['response']['groups']['0']['items']['0']['tips']['0']; //<div style="align:center;"> foreach ( $items0+$items1 as $item){ echo '<li>'; echo $item['name']; echo $item['text']; } foreach ( $items2 as $item){ print $item['firstName']; print '&nbsp'; print $item['lastName']; } Here is encode JSON array(2) { ["meta"]=> array(2) { ["code"]=> int(200) ["requestId"]=> string(24) "55fb1f91498e70ad2e246eed" } ["response"]=> array(10) { ["suggestedFilters"]=> array(2) { ["header"]=> string(12) "Tap to show:" ["filters"]=> array(2) { [0]=> array(2) { ["name"]=> string(13) "With specials" ["key"]=> string( "specials" } [1]=> array(2) { ["name"]=> string( "Open now" ["key"]=> string(7) "openNow" } } } ["geocode"]=> array( { ["what"]=> string(0) "" ["where"]=> string(6) "london" ["center"]=> array(2) { ["lat"]=> float(51.50853) ["lng"]=> float(-0.12574) } ["displayString"]=> string(38) "London, Greater London, United Kingdom" ["cc"]=> string(2) "GB" ["geometry"]=> array(1) { ["bounds"]=> array(2) { ["ne"]=> array(2) { ["lat"]=> float(51.691643999656) ["lng"]=> float(0.33418999705203) } ["sw"]=> array(2) { ["lat"]=> float(51.284674044171) ["lng"]=> float(-0.50855792793694) } } } ["slug"]=> string(6) "london" ["longId"]=> string(17) "72057594040571679" } ["warning"]=> array(1) { ["text"]=> string(114) "There aren't a lot of results near you. Try something more general, reset your filters, or expand the search area." } ["headerLocation"]=> string(6) "London" ["headerFullLocation"]=> string(6) "London" ["headerLocationGranularity"]=> string(4) "city" ["query"]=> string(4) "food" ["totalResults"]=> int(246) ["suggestedBounds"]=> array(2) { ["ne"]=> array(2) { ["lat"]=> float(51.510800358799) ["lng"]=> float(-0.12174369837641) } ["sw"]=> array(2) { ["lat"]=> float(51.508100699014) ["lng"]=> float(-0.13015278468604) } } ["groups"]=> array(1) { [0]=> array(3) { ["type"]=> string(18) "Recommended Places" ["name"]=> string(11) "recommended" ["items"]=> array(1) { [0]=> array(4) { ["reasons"]=> array(2) { ["count"]=> int(0) ["items"]=> array(1) { [0]=> array(3) { ["summary"]=> string(20) "This spot is popular" ["type"]=> string(7) "general" ["reasonName"]=> string(23) "globalInteractionReason" } } } ["venue"]=> array(17) { ["id"]=> string(24) "53bab96d498e7e355fb53d6c" ["name"]=> string(9) "Barrafina" ["contact"]=> array(6) { ["phone"]=> string(13) "+442074401456" ["formattedPhone"]=> string(16) "+44 20 7440 1456" ["twitter"]=> string(13) "barrafinaadst" ["facebook"]=> string(15) "705351912878392" ["facebookUsername"]=> string(23) "BarrafinaAdelaideStreet" ["facebookName"]=> string(25) "Barrafina Adelaide Street" } ["location"]=> array(10) { ["address"]=> string(14) "10 Adelaide St" ["crossStreet"]=> string(13) "William IV St" ["lat"]=> float(51.509450528906) ["lng"]=> float(-0.12594824153122) ["postalCode"]=> string( "WC2N 4HZ" ["cc"]=> string(2) "GB" ["city"]=> string(6) "London" ["state"]=> string(14) "Greater London" ["country"]=> string(14) "United Kingdom" ["formattedAddress"]=> array(5) { [0]=> string(30) "10 Adelaide St (William IV St)" [1]=> string(6) "London" [2]=> string(14) "Greater London" [3]=> string( "WC2N 4HZ" [4]=> string(14) "United Kingdom" } } ["categories"]=> array(1) { [0]=> array(6) { ["id"]=> string(24) "4bf58dd8d48988d150941735" ["name"]=> string(18) "Spanish Restaurant" ["pluralName"]=> string(19) "Spanish Restaurants" ["shortName"]=> string(7) "Spanish" ["icon"]=> array(2) { ["prefix"]=> string(52) "https://ss3.4sqi.net/img/categories_v2/food/spanish_" ["suffix"]=> string(4) ".png" } ["primary"]=> bool(true) } } ["verified"]=> bool(false) ["stats"]=> array(3) { ["checkinsCount"]=> int(357) ["usersCount"]=> int(278) ["tipCount"]=> int(26) } ["url"]=> string(22) "http://barrafina.co.uk" ["price"]=> array(3) { ["tier"]=> int(2) ["message"]=> string( "Moderate" ["currency"]=> string(2) "£" } ["rating"]=> float(9) ["ratingColor"]=> string(6) "00B551" ["ratingSignals"]=> int(80) ["allowMenuUrlEdit"]=> bool(true) ["hours"]=> array(2) { ["status"]=> string(19) "Open until 11:00 PM" ["isOpen"]=> bool(true) } ["specials"]=> array(2) { ["count"]=> int(0) ["items"]=> array(0) { } } ["photos"]=> array(2) { ["count"]=> int(31) ["groups"]=> array(0) { } } ["hereNow"]=> array(3) { ["count"]=> int(0) ["summary"]=> string(11) "Nobody here" ["groups"]=> array(0) { } } } ["tips"]=> array(1) { [0]=> array(9) { ["id"]=> string(24) "55db9142498ede18f5b31b81" ["createdAt"]=> int(1440452930) ["text"]=> string(164) "Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here." ["type"]=> string(4) "user" ["canonicalUrl"]=> string(52) "https://foursquare.com/item/55db9142498ede18f5b31b81" ["likes"]=> array(3) { ["count"]=> int(2) ["groups"]=> array(0) { } ["summary"]=> string(7) "2 likes" } ["logView"]=> bool(true) ["todo"]=> array(1) { ["count"]=> int(0) } ["user"]=> array(5) { ["id"]=> string( "98683884" ["firstName"]=> string(4) "Matt" ["lastName"]=> string(6) "Ta-Min" ["gender"]=> string(4) "male" ["photo"]=> array(2) { ["prefix"]=> string(31) "https://irs1.4sqi.net/img/user/" ["suffix"]=> string(30) "/98683884-1MJ0OTISTPZWSBRJ.jpg" } } } } ["referralId"]=> string(30) "e-3-53bab96d498e7e355fb53d6c-0" } } } } } } Here is JSON {"meta":{"code":200,"requestId":"55fbde58498e7fdbd12f8fb2"},"response":{"suggestedFilters":{"header":"Tap to show:","filters":[{"name":"With specials","key":"specials"},{"name":"Open now","key":"openNow"}]},"geocode":{"what":"","where":"london","center":{"lat":51.50853,"lng":-0.12574},"displayString":"London, Greater London, United Kingdom","cc":"GB","geometry":{"bounds":{"ne":{"lat":51.691643999655895,"lng":0.33418999705203406},"sw":{"lat":51.28467404417054,"lng":-0.5085579279369435}}},"slug":"london","longId":"72057594040571679"},"warning":{"text":"There aren't a lot of results near you. Try something more general, reset your filters, or expand the search area."},"headerLocation":"London","headerFullLocation":"London","headerLocationGranularity":"city","query":"food","totalResults":246,"suggestedBounds":{"ne":{"lat":51.5108003587992,"lng":-0.12174369837640672},"sw":{"lat":51.50810069901375,"lng":-0.1301527846860385}},"groups":[{"type":"Recommended Places","name":"recommended","items":[{"reasons":{"count":0,"items":[{"summary":"This spot is popular","type":"general","reasonName":"globalInteractionReason"}]},"venue":{"id":"53bab96d498e7e355fb53d6c","name":"Barrafina","contact":{"phone":"+442074401456","formattedPhone":"+44 20 7440 1456","twitter":"barrafinaadst","facebook":"705351912878392","facebookUsername":"BarrafinaAdelaideStreet","facebookName":"Barrafina Adelaide Street"},"location":{"address":"10 Adelaide St","crossStreet":"William IV St","lat":51.50945052890648,"lng":-0.1259482415312226,"postalCode":"WC2N 4HZ","cc":"GB","city":"London","state":"Greater London","country":"United Kingdom","formattedAddress":["10 Adelaide St (William IV St)","London","Greater London","WC2N 4HZ","United Kingdom"]},"categories":[{"id":"4bf58dd8d48988d150941735","name":"Spanish Restaurant","pluralName":"Spanish Restaurants","shortName":"Spanish","icon":{"prefix":"https:\/\/ss3.4sqi.net\/img\/categories_v2\/food\/spanish_","suffix":".png"},"primary":true}],"verified":false,"stats":{"checkinsCount":357,"usersCount":278,"tipCount":26},"url":"http:\/\/barrafina.co.uk","rating":9.0,"ratingColor":"00B551","ratingSignals":80,"allowMenuUrlEdit":true,"hours":{"status":"Closed until Noon","isOpen":false},"specials":{"count":0,"items":[]},"photos":{"count":31,"groups":[]},"hereNow":{"count":0,"summary":"Nobody here","groups":[]}},"tips":[{"id":"55db9142498ede18f5b31b81","createdAt":1440452930,"text":"Exceptional cooking here. Such simple but amazing dishes. Highly recommend the crab croquettes, lambs kidneys, skewers and the brain. Sherries are also superb here.","type":"user","canonicalUrl":"https:\/\/foursquare.com\/item\/55db9142498ede18f5b31b81","likes":{"count":2,"groups":[],"summary":"2 likes"},"logView":true,"todo":{"count":0},"user":{"id":"98683884","firstName":"Matt","lastName":"Ta-Min","gender":"male","photo":{"prefix":"https:\/\/irs1.4sqi.net\/img\/user\/","suffix":"\/98683884-1MJ0OTISTPZWSBRJ.jpg"}}}],"referralId":"e-3-53bab96d498e7e355fb53d6c-0"}]}]}}
  18. I have created a JSON file from the database, which has two table semone with attributes id, semester, cname and table courses with attributes coname and credit. Code I am writing in php is following. main.php <?php $user = "root"; $password = ""; $database = "scheduler"; $con = mysqli_connect("localhost", $user, $password, $database) or die ("Unable to connect"); $query = "SELECT semone.userid AS sbuid, semone.semester AS semester, semone.cname AS name, courses.credit AS value, courses.progskill AS skill FROM semone INNER JOIN courses ON semone.cname = courses.coname" ; $result = mysqli_query($con,$query)or die ("Unable to connect"); $info = array(); $test = array(); while ($row = $result->fetch_array(MYSQLI_ASSOC)) { $row['xyz'] = array( 'name'=> $row['name'], 'value'=> $row['value'] ); $info[$row['semester']]['children'][]= $row['xyz']; $data = json_encode(array('id' => $row['sbuid'], 'children' => $info)); } echo $data; ?> I want to get JSON file as seen in the following code, but I am getting something like this. **output.json** {"id":"12345", "children": {"first": {"children": [{"name":"CSE101","value":"100"}, {"name":"CSE102","value":"100"}]}, "second": {"children": [{"name":"CSE103","value":"50"}, {"name":"CSE104","value":"100"}, {"name":"CSE105","value":"100"}]}, "third": {"children": [{"name":"CSE106","value":"50"}]} }} But this is what I am expecting. **expected.json** { "id": 12345, "children": [{ "semester": "first", "children": [{ "name": "C101","value": 100}, { "name": "C102","value": 100}] }, { "semester": "second", "children": [{ "name": "C103", "value": 50}, {"name": "C104","value": 100}, {"name": "C105","value": 100}] }, { "semester": "third", "children": [{"name": "C106","value": 50}] } }
  19. Fabian

    Regexp

    Mein derzeitiger Regex: \b[^]?(lvl7)[^]?\b Habe folgenden String: "lvl7 alvl7 lvl7b" Nun will ich das er mir nur "alvl7" und "lvl7b" ausgibt und kein lvl7 also er soll dieses lvl7 nehmen weil das wir später durch eine variable ersetzt und schauen ob das davor und/oder dahinter noch was stehen hat aber nicht nur die variable allein.
  20. Hi, I'm trying to merge the JSON results of playlists returned from soundcloud.com although I'm having some trouble getting this to display correctly. The results are being displaying nested, where am I going wrong and how can I get this to merge so there is just one array with three sets of data. Check the image of how it is displayed at the moment Any help would be amazing, thanks you in advance <?php $playlists = array( 'https://api.soundcloud.com/playlists/121967270/?&client_id=###', 'https://api.soundcloud.com/playlists/121906753/?&client_id=###', 'https://api.soundcloud.com/playlists/121906816/?&client_id=###' ); $json = array(); foreach ($playlists as $playlist) { $data = json_decode(file_get_contents($playlist)); $json = array_merge(array($json, $data)); } $json = json_encode($json); header('Content-Type: application/json'); echo $json; ?>
  21. hello, i am new in php and i would like to develop a login screen in android. my server side is developed in php and for some reason i get every request the follwoing error: "no such file or directory". i have 1 index file and 3 files insdie the "include" directory. this is my files code: index.php <?php /** * Created by PhpStorm. * User: matant * Date: 4/29/2015 * Time: 4:57 PM */ $data = $_SERVER['HTTP_JSON']; $data = json_decode($data); $temp = $data->tag; if($temp == 'login') { $tag = $data->tag; $temp = 'insdieif'; require_once 'include/DB_Functions.php'; $db = new DB_Functions(); $response = array("tag" => $tag, "error"=>FALSE); //login if($tag == 'login') { $email = $data->email; $password = $data->password; $user = $db->getUserDet($email,$password); if($user != false){ $response["error"] = FALSE; $response["user"]["username"] = $user["usern"]; $response["user"]["email"] = $user["email"]; echo json_encode($response); }else { $response["error"] = true; $response["error_msg"] = "Incorrect Email or Password!"; echo json_encode($response); } }else { $response["error"] = true; $response["error_msg"] = "This is not Login request!"; echo json_encode($response); } } else { $response["tag"] = $temp; $response["error"] = true; $response["error_msg"] = "tag parameter is missing"; echo json_encode($response); } DB_Functions.php <?php /** * Created by PhpStorm. * User: matant * Date: 4/29/2015 * Time: 3:57 PM */ class DB_Functions { private $db; function _contrust() { require_once 'DB_Connect.php'; $this->db = DB_Connect(); $this->db->connect(); echo $this->db; } function _destruct() { // $this->close(); } public function getUserDet($email, $pass) { $res = mysql_query("SELECT * FROM users WHERE email = '$email'") or die (mysql_error()); $num_of_rows = mysql_num_rows($res); if ($num_of_rows > 0) { $res = mysql_fetch_array($res); $restemp = $res['password']; if ($pass == $restemp) return $res; else return false; } } } ?> DB_Connect.php: <?php /** * Created by PhpStorm. * User: matant * Date: 4/29/2015 * Time: 3:47 PM */ class DB_Connect{ function _construct(){ } function _destruct(){ } public function connect(){ require_once 'Config.php'; $con = mysql_connect("DB_Host","DB_User","DB_password"); if(!$con) { die('could not connect:'.mysql_error()); } else { mysql_select_db(DB_database, $con); } return $con; } public function close() { mysql_close(); } } ?> Config.php: <?php /** * Created by PhpStorm. * User: matant * Date: 4/29/2015 * Time: 3:35 PM */ define("DB_Host","sqlserver"); define("DB_User","user"); define("DB_password","pass"); define("DB_database","b12_16183751_gpsport"); ?>
  22. Hi, I've got this JSON output: {"result":"success","clientid":null,"serviceid":null,"pid":null,"domain":"testdomain.com","totalresults":"1","startnumber":0,"numreturned":1,"products":{"product":[{"id":"3804","clientid":"1401","orderid":"3276","pid":"53","regdate":"2010-02-14","name":"Basic","groupname":"Plans","domain":"testdomain.com","dedicatedip":"","serverid":"4","servername":"serverx.com","serverip":"123.123.123.123","serverhostname":"","firstpaymentamount":"7.99","recurringamount":"7.99","paymentmethod":"wibble","paymentmethodname":"Credit\/Debit Card","billingcycle":"Monthly","nextduedate":"2010-02-14","status":"Terminated","username":"dcdqw","password":"z1nmY1p4Y9","subscriptionid":"","promoid":"0","overideautosuspend":"","overidesuspenduntil":"0000-00-00","ns1":"","ns2":"","assignedips":"","notes":"","diskusage":"0","disklimit":"1000","bwusage":"0","bwlimit":"50000","lastupdate":"2015-05-01 06:01:17","customfields":{"customfield":[{"id":"36","name":"ThisUserID","value":"1243214"}]},"configoptions":{"configoption":[]}}]}} ... and I'm trying to get the value for ThisUserID but I'm struggling so much with the arrays! I've copied it into http://jsonviewer.stack.hu so I can understand it more but just can't get that value. I understand: $clientid = $arr->clientid; ... but can't work out how to drill deeper. Any help appreciated
  23. Hi I have a json data : { "email": "john@john.fr", "line_items": [ { "sku": "123456789", "price": "0.67", "price_with_tax": "4.00", "tax_lines": [ { "title": "tax010", "rate": 0.01, "price": "1.11" }, { "title": "tax00200", "rate": 0.02, "price": "2.22" } ] }, { "sku": "012345666", "price": "1.67", "price_with_tax": "5.00", "tax_lines": [ { "title": "tax0003000", "rate": 0.03, "price": "3.33" } ] } ] } and I try put this data in mySql. First data have a good value but second have a wrong data on 'price_tax1' and 'price_tax2' in mySql : Here is my MySql 1st item :::: good value email:john@john.fr sku:123456789 price:0.67 price_with_tax:4.00 price_tax1:1.11 price_tax2:2.22 2nd item :::: email:john@john.fr sku:012345666 price:1.67 price_with_tax:5.00 wrong value :::: price_tax1:1.11 price_tax2:2.22 here is my code : $jsondata = file_get_contents($jsondata); $dataDecode = json_decode($jsondata); $email = $dataDecode->email; try { $dtbs = new PDO($dsn_dev, $pdo_user, $pdo_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); } catch (Exception $e) { die('Error : ' . $e->getMessage()); } try { foreach ($dataDecode->line_items as $obj) { $var_sku = $obj->sku; $var_price = $obj->price; $var_price_with_tax = $obj->price_with_tax; $taxNewArray = array(); foreach ($dataDecode->line_items[0]->tax_lines as $obj2) { array_push($taxNewArray , $obj2); } $val1st = array_shift($taxNewArray); $val2nd = array_pop ($taxNewArray); $var_tax1 = $val1st->price; $var_tax2 = $val2nd->price; $stmt = $dtbs->prepare("INSERT INTO $tabledata ($mysql_email, $mysql_sku, $mysq_price, $mysql_price_with_tax, $mysql_price__tax1___line_items, $mysql_price__tax2___line_items ) VALUES (:email, :sku, :price, :price_with_tax, :price_tax1, :price_tax2)"); $stmt->execute(array(':email'=>$email, ':sku'=>$var_sku, ':price'=>$var_price, ':price_with_tax'=>$var_price_with_tax, ':price_tax1'=>$var_tax1, ':price_tax2'=>$var_tax2 )); } } catch(Exception $e) { throw $e; } How can I put goog value of 2nd data in mySql ? thanks
  24. I am trying to display Json data using PHP but I have ran into a problem. This is the json: }, { "node_title": "Room", "Room description": "This is Room 1", "Room name": "Room 1", "Room Type": "Bedroom", "Room attributes": [ ] }, { "node_title": "Room", "Room description": "This is Room 2", "Room name": "Room 2", "Room Type": "Bedroom", "Room attributes": [ This is my PHP: <?php $code = isset($_POST['search']) ? $_POST['search'] : '123nocode123456'; $roomjson = file_get_contents("http://my.json.com/". $code); $roomobj = json_decode($roomjson); ?> <?php echo '<div role="tabpanel"> <ul class="nav nav-tabs" role="tablist"> <li role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>'; if (empty($roomobj)) { echo '</div>'; }else{ if ($roomobj{0}->{'Room Type'} == 'Bedroom') { echo '<li role="presentation"><a href="#bedroom1" aria-controls="bedroom1" role="tab" data-toggle="tab">'; echo ($roomobj{0}->{'Room name'}); echo '</a></li></div>'; ?> The problem is, I have two json 'nodes' that have the same 'Room Type' value, so how can I differentiate between the two? But I need to display both of them. I think I can use foreach but I need the values 'Room Name' to be in separate <li>.
  25. Hi, My codes does not show any Latitude or Longitude but it did last night when I started writing this code?! $postcode = 'BN113ED'; $response = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($postcode) . '&sensor=true'); $response = json_decode($response); $lat = $response->results[0]->geometry->location->lat; $long = $response->results[0]->geometry->location->lng; here is the URL that shows the JSON http://maps.googleapis.com/maps/api/geocode/json?address=bn113ed&sensor=true
×
×
  • 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.