PHP - Mysql Php And Json
help required for noobie(no hair left)
all i want to be able to do is use the individual elements of the array in javascript eg companyname or companyimage but just getting my head in my hand. mysql_select_db("herefordinfo") or die(mysql_error()); echo "Connected to Database"; $dbQuery = 'SELECT * FROM companies'; $dbResult = mysql_query($dbQuery) or die ("Could not read data because " . mysql_error()); $RowCount = mysql_numrows($dbResult); while ($pubs = mysql_fetch_assoc($dbResult)) { $array[] = "{ {$pubs['id']}, {$pubs['companyname']}, {$pubs['companyinfo']}, {$pubs['companyimage']} }"; } echo 'var pub = [' . implode(', ', $array) . '];'; // this ?> <html> <head> <script type="text/javascript"> var jsArray = <?php echo json_encode($array); ?>; document.write(jsArray); //this </script> </head> <boby></body> </html> both php and javescritp output the results below { 1, lichfield vaults, 10 church street hereford , lich.jpg },{ 2, Black Lion, bridge street, blacklion.jpg },{ 3, Saracens Head, st martins street, saracens.jpg } Similar Tutorialshi all i have some json that i want to decode and add to mysql could you give me some help? i need to add each of these as a row here is the json Code: [Select] [ { "DayNumber": 1, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 1, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 1, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 1, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 1, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 2, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 2, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 2, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 2, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 2, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 2, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 83, "Room": "G3" }, { "DayNumber": 3, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:30:00 AM", "DefinitionTimeTo": "9:25:00 AM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 1455, "Room": "G3" }, { "DayNumber": 3, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:25:00 AM", "DefinitionTimeTo": "10:15:00 AM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 3, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:35:00 AM", "DefinitionTimeTo": "11:30:00 AM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 3, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:30:00 AM", "DefinitionTimeTo": "12:15:00 PM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 3, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10C9H1", "ClassDescription": "Chapel", "StaffID": 1071, "Room": "C1" }, { "DayNumber": 3, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "A3" }, { "DayNumber": 4, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 4, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 4, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 4, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 4, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 5, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 5, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 5, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 5, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 5, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 6, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 6, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 6, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10C9H1", "ClassDescription": "Chapel", "StaffID": 1071, "Room": "C1" }, { "DayNumber": 6, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 6, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 6, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 7, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 7, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CWA1", "ClassDescription": "Web Authoring", "StaffID": 607388, "Room": "CY34" }, { "DayNumber": 7, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 1455, "Room": "G3" }, { "DayNumber": 7, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 8, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:30:00 AM", "DefinitionTimeTo": "9:25:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "S21" }, { "DayNumber": 8, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:25:00 AM", "DefinitionTimeTo": "10:15:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "S21" }, { "DayNumber": 8, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:35:00 AM", "DefinitionTimeTo": "11:30:00 AM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 8, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:30:00 AM", "DefinitionTimeTo": "12:15:00 PM", "ClassCode": "10APX4", "ClassDescription": "Photography", "StaffID": 620143, "Room": "CY14" }, { "DayNumber": 8, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 8, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 9, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10P9D6", "ClassDescription": "Physical Development", "StaffID": 83, "Room": "G3" }, { "DayNumber": 9, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" }, { "DayNumber": 9, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 9, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10CBP1", "ClassDescription": "Programming ", "StaffID": 607388, "Room": "CY17" }, { "DayNumber": 9, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 9, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "S23" }, { "DayNumber": 10, "PeriodNumber": 1, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 1, "DefinitionTimeFrom": "8:50:00 AM", "DefinitionTimeTo": "9:45:00 AM", "ClassCode": "10GHZ6", "ClassDescription": "Hazard Geography", "StaffID": 608055, "Room": "S22" }, { "DayNumber": 10, "PeriodNumber": 2, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 2, "DefinitionTimeFrom": "9:45:00 AM", "DefinitionTimeTo": "10:35:00 AM", "ClassCode": "10F9M1", "ClassDescription": "Form Period", "StaffID": 615792, "Room": "T11" }, { "DayNumber": 10, "PeriodNumber": 3, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 3, "DefinitionTimeFrom": "10:55:00 AM", "DefinitionTimeTo": "11:50:00 AM", "ClassCode": "10M9B5", "ClassDescription": "Mainstream Mathematics 2", "StaffID": 625461, "Room": "A4" }, { "DayNumber": 10, "PeriodNumber": 4, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 4, "DefinitionTimeFrom": "11:50:00 AM", "DefinitionTimeTo": "12:40:00 PM", "ClassCode": "10AMS2", "ClassDescription": "Media Studies", "StaffID": 622915, "Room": "CY14" }, { "DayNumber": 10, "PeriodNumber": 5, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 5, "DefinitionTimeFrom": "1:30:00 PM", "DefinitionTimeTo": "2:25:00 PM", "ClassCode": "10QCS5", "ClassDescription": "Literacy - Curriculum Support2", "StaffID": 601807, "Room": "A1" }, { "DayNumber": 10, "PeriodNumber": 6, "PeriodNumberSeq": 1, "DefinitionPeriodNumber": 6, "DefinitionTimeFrom": "2:25:00 PM", "DefinitionTimeTo": "3:15:00 PM", "ClassCode": "10EWB2", "ClassDescription": "Writing Workshop 1", "StaffID": 619597, "Room": "T22" } ] thanks Matt I have a simple ajax that passes data to a php script using jquery serialize. This is working good but where I am getting stuck is trying to pass json array into mysql. The json is outputting the correct data, but when I insert into db, it just says Array in the field. How can I convert(if that is the right term) json array to use in mysql. In the code I have posted, $box is an array from jquery which I normally use foreach to loop through array. What I need to do is convert $box after is has been encoded. Thanks Code: [Select] $box = $_POST['BRVbrtrv_boxnumber']; $list = array("activity" => $activity, "mobile" => $mobile, "company" => $company, "authorised" => $authorised, "service" => $service, "department" => $department, "address" => $address, "boxcount" => $boxcount, "box" => $box); $c = json_encode($list); echo $c; Hi, I have a problem with some code not working. I need it to get the data from a mysql database and then export it as a json array in the format of id , title, author, date, imageUrl, text. (Please not that these are all variables ) PHP CODE: Code: [Select] <?php $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; $arr = array(); $rs = ("SELECT `id`, `title`, `author`, `date`, `imageUrl`, `text` FROM `items`"); while($obj = mysql_query($rs)) { $arr[0] = $obj->id; $arr[1] = $obj->title; $arr[2] = $obj->author; $arr[3] = $obj->date; $arr[4] = $obj->imageUrl; $arr[5] = $obj->text; } echo '{"items":'.json_encode($arr).'}'; ?> Thanks For Your Help borden0108 Hi, I have the following code that takes a list from a mySQL db and puts it into an array that shows 'gig date, venue, city' per entry: - Code: [Select] while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $array[] = ($row['date'].', '.$row['gl_venue'].', '.$row['gl_city']); } $output = json_encode($array); this outputs JSON like so: Code: [Select] ["06-05-2011, O'neills, Southend","07-05-2011, Power League, Peterborough","14-05-2011, Queen Victoria hall, Oundle",.......] how do I add keys into the array so I get something like: Code: [Select] {"gigs":[ { "gig": "date, venue, city",} ]} at least I think so anyway!?! What I want to do is eventually be able to parse a JSON listing into Objective-C and be able to call key/pairs into various different parts of an app. I'm pretty new to this so any advice would be great.
An affiliate marketer refers some products which are stored in a simple array. $all_items_sold = '{"7777":{"item":"hammer","price":"4.99"},"8888":{"item":"nail","price":"1.99"},"9999":{"item":"apple","price":"2.00"}}'; $referred_by_Affiliate = array('1234','8888','7777');
So, out of all the 3 items that sold, only 2 of them were referred by the affiliate marketer.
Currently I do this:
Is there a "best practices" way to accomplish this?
Thank you. Hi, This is an odd one (to me anyway). I've created an API for deploying gig information in either XML or JSON format. It works fine as it is, both formats of output giving me what I want. When I take out the mySQL login information and replace it with "include 'connect_include.php';" (where the file connect_include.php contains the exact login code that I replced). The JSON output works fine but the XML output doesn't run. What could be causing this?? JSON API: -http://www.api.the-guards.co.uk/jsontest.php?apikey=123456&format=json XML API: - http://www.api.the-guards.co.uk/jsontest.php?apikey=123456&format=xml API code: Code: [Select] <?php if (($_GET['apikey'])==123456 and isset($_GET['format'])){ //Set variables $format = strtolower($_GET['format']); //Connect to the Database include 'connect_include.php'; //Run our query $result = mysql_query(' SELECT * FROM tg_gig_list where gl_date >= curdate() and gl_publish = 1 order by gl_date '); //Preapre our output if($format == 'json') { while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $array[] = array($row['gl_date']=>($row['gl_venue'].', '.$row['gl_city'])); }; $output = json_encode($array); //Output the output. echo $output; header('Content-type: application/json'); } elseif($format == 'xml') { header('Content-type: text/xml'); $output = "<?xml version=\"1.0\"?>\n"; $output .= "<tggiglist>\n"; for($i = 0 ; $i < mysql_num_rows($result) ; $i++){ $row = mysql_fetch_assoc($result); $output .= "<giglist> \n"; $output .= "<giglist_date>" . $row['gl_date'] . "</giglist_date> \n"; $output .= "<giglist_venue>" . $row['gl_venue'] . "</giglist_venue> \n"; $output .= "<giglist_city>" . $row['gl_city'] . "</giglist_city> \n"; $output .= "</giglist> \n"; } $output .= "</tggiglist>"; } } else { die ('no way'); } //output the output echo $output; ?> Contents of 'connect_include.php: Code: [Select] <?php mysql_connect("database.lcn.com", "dbname", "password") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); ?> .....this is the same code that I replaced. Obviously, the 'connect' works ok as the JSON version runs fine. There's something being added to the scripting when I use the include file that isn't there when the code goes straight in.....I think???? Hi
I have another problem with my code
I have records in my database and i want to put them in Jgrid but no records are show.
This is my php
<?php error_reporting(0); require_once 'database_connection.php'; $page = $_GET['page']; // get the requested page $limit = $_GET['rows']; // get how many rows we want to have into the grid $sidx = $_GET['sidx']; // get index row - i.e. user click to sort $sord = $_GET['sord']; // get the direction if(!$sidx) $sidx =1; // connect to the database $result = mysql_query("SELECT COUNT(*) AS count FROM utilizador"); $row = mysql_fetch_array($result,MYSQL_ASSOC); $count = $row['count']; if( $count >0 ) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } if ($page > $total_pages) $page=$total_pages; $start = $limit*$page - $limit; // do not put $limit*($page - 1) $SQL = "SELECT * FROM utilizador ORDER BY $sidx $sord LIMIT $start , $limit"; $result = mysql_query( $SQL ) or die("Couldn t execute query.".mysql_error()); $responce->page = $page; $responce->total = $total_pages; $responce->records = $count; $i=0; while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { $responce->rows[$i]['id']=$row[idutilizador]; $responce->rows[$i]['cell']=array($row[idutilizador],$row[nome],$row[utilizador],$row[telefone],$row[email]); $i++; } echo json_encode($responce); ?>And this is the Jgrid <html> <head> <title>jQGrid example</title> <!-- Load CSS--><br /> <link rel="stylesheet" href="css/ui.jqgrid.css" type="text/css" media="all" /> <!-- For this theme, download your own from link above, and place it at css folder --> <link rel="stylesheet" href="css/jquery-ui-1.9.2.custom.css" type="text/css" media="all" /> <!-- Load Javascript --> <script src="js/jquery_1.5.2.js" type="text/javascript"></script> <script src="js/jquery-ui-1.8.1.custom.min.js" type="text/javascript"></script> <script src="js/i18n/grid.locale-pt.js" type="text/javascript"></script> <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script> </head> <body> <table id="datagrid"></table> <div id="navGrid"></div> <p><script language="javascript"> jQuery("#datagrid").jqGrid({ url:'example.php', datatype: "json", colNames:['Idutilizador','Nome', 'Utilizador', 'Telefone','Email'], colModel:[ {name:'idutilizador',index:'idutilizador', width:55,editable:false,editoptions:{readonly:true,size:10}}, {name:'nome',index:'nome', width:80,editable:true,editoptions:{size:10}}, {name:'idutilizador',index:'idutilizador', width:90,editable:true,editoptions:{size:25}}, {name:'telefone',index:'telefone', width:60, align:"right",editable:true,editoptions:{size:10}}, {name:'email',index:'email', width:60, align:"right",editable:true,editoptions:{size:10}} ], rowNum:10, rowList:[10,15,20,25,30,35,40], pager: '#navGrid', sortname: 'idutilizador', sortorder: "asc", height: 500, width:900, viewrecords: true, caption:"Atividades Registadas" }); jQuery("#datagrid").jqGrid('navGrid','#navGrid',{edit:true,add:true,del:true}); </script> </body> </html>Anything wrong with the code? Regards Hello - I am connecting to MySql and running a query. If I use a foreach loop, I can iterate over the results and have them print to screen. However, when I try the below everything is null!
How can I add the results of my MySql query to a php array?
<?php $con=mysqli_connect("site", "user", "psasswr=ord", "db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT * FROM test LIMIT 10"; $result = mysqli_query($con,$sql); echo json_encode($result); mysqli_free_result($result); mysqli_close($con); ?>
but what this prints is: {"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null} I am using multiple levels of JSON data coming into php from a C# application, as in:
return new RootObject() { ID_Project = 4, Name_Project = "Test", Receiver_ID = 4, Receiver_Name = "ABCDE", UserID = 20, UserRole = new User_Role() { ID_User = 20, Role_User = "level 3", User_Role_Description = "U", UserGroup = new List<user_group>() { new User_Group() { ID_UserGroup = 30, Name_UserGroup = "usergroup8", UserID = 20 }, new User_Group() { ID_UserGroup = 31, Name_UserGroup = "usergroup9", UserID = 21 }, new User_Group() { ID_UserGroup = 32, Name_UserGroup = "usergroup10", UserID = 22 } } } }; i am having troubles accessing the second level: UserRole and 3rd level: User_Group in my php script. im currently trying like this: foreach ($phpArray as $key => $value) { echo "<h2>$key</h2>"; foreach ($value as $k => $v) { echo "$k | $v "; foreach ($v as $key1) { echo "$key1 "; } } } does anyone have an idea? Thanks, Revathy Please see http://www.socialnewsoffice.com/blog_posts?&display=2&api_key=b5cbd66dca99c49d1a6c3d which out puts a json response like this Code: [Select] [{ "blog_id":"3", "post_date":"Sat, 14 April 2012", "post_title":"Facebook's New Fan Page Learn How To Use Features", "article_img":"http:\/\/www.socialnewsoffice.com\/uploads\/17963.jpg", "post_content":"<p>This week saw the release of Facebook's latest functionality changes (Timeline for Businesses) that will shape the future of how businesses will market their campaigns, through the social media giant Facebook. A number of marketers are wondering how they will incorporate the new features in an attempt to progress and move forward with their online social media presence.<\/p>\r\n<p>Taking all the key changes in to consideration we have managed to create a guide on how to smoothly move with the times and embrace the new Facebook layout.<\/p>\r\n<p>Please read on below for helpful tips and tricks on how to excel with 'Timeline for Brands'<\/p>\r\n<h2>New Features Announced at the Facebook Marketing Conference:<\/h2>\r\n<p><strong>View and Apps:<\/strong> What was once known as Application pages has changed to 'Tabs'. These can now have customizable images linked with them and the order of them can be changed too. Below you can see from the screenshot what a customized Facebook Timeline looks like.<\/p>\r\n<p><strong>Pinning Content:<\/strong> With this new feature you can 'pin' a post to the very top of your Facebook Timeline. This is Very effective when working on a new campaign and is a great way to entice increased traffic to your tab or application page.<\/p>\r\n<p><strong>Featured 'Starred' Content:<\/strong> This feature allows you to select key content or imagery and extend it so it fits across your entire page. Therefore giving you featured content on your Facebook Timeline and making it more visible.<\/p>\r\n<p><strong>Cover Photos:<\/strong> Cover Photos are another great new feature that allow you to announce your latest campaign, welcome your following community or just simply show visitors to your timeline what you can do. There are some slight flaws with this feature though and will be addressed below.<\/p>\r\n<p><strong>Page Dimensions:<\/strong> Dimensions of application pages has now changed with the release of Facebook Timeline. If you happen to be an SML user then you have all the tools necessary to update your page on your own. If your using Involvers App Suite then those applications will be updated soon.<\/p>\r\n<p><strong>Removal of Default Landing Pages:<\/strong> The commonly used Facebook landing pages have been removed and replaced with various options to allow brands to drive content to application pages. These options allow you to use your cover photo and pinned content to attract users to your personal application pages. Despite the changes it is however still possible to link directly to application pages from ads, posts and outside of Facebook.<\/p>\r\n<h2>Getting Started with Timeline For Brand:<\/h2>\r\n<p>Firstly when accessing and logging in to your New Facebook Brand Page, you will see this admin message displayed below:<\/p>\r\n<p>When will my Page change to the latest design?<\/p>\r\n<p>To see a preview of what your new pages will look like, simply click on the green button at the top of your current pages. A second option is to wait until March 30th 2012 when all pages will be upgraded automatically.<\/p>\r\n<p>Where can I visit to learn more about how to use the new Pages?<\/p>\r\n<p><strong>There are a number of places you can visit to learn all you need to know about Pages:<\/strong><\/p>\r\n<ul>\r\n<li>To find out more about new features, download the Pages Overview guide by clicking here.<\/li>\r\n<li>If your wondering how to get started with Pages then download Facebook's full Pages Product Guide by clicking here.<\/li>\r\n<li>The Pages Learning video allows you to walk through the key features with Facebook's product experts.<\/li>\r\n<li>If you need answers to specific questions, visit Facebook's Help Centre.<\/li>\r\n<\/ul>\r\n<h2>How should I choose a cover photo for my Page?<\/h2>\r\n<p>Firstly select a unique image that represents your page. Facebook itself recommends using a photo of a popular menu item, album artwork or an image of your product being used by someone. You need to experiment with a number of different images that your audience responds positively to. Few key elements of Cover Images:<\/p>\r\n<p><strong>Each Cover image must be at least 399 pixels wide and must not contain the following:<\/strong><\/p>\r\n<ul>\r\n<li>Prices \/ Purchase information and displaying offers such as \"60% off this month\" are not permitted. Also 'Download this from our website' is not allowed.<\/li>\r\n<li>No email addresses, web addresses and any other contact information.<\/li>\r\n<li>References to clicking on or the use of Facebook interface elements such as Like or Share or any other Facebook Features.<\/li>\r\n<li>\"Tell your friends\" or \"Get it now\" or any other calls to action are not allowed in the latest version of Facebook Timeline.<\/li>\r\n<\/ul>\r\n<p>All Timeline cover imagery is public and therefore means anyone visiting your Page will be able to see exactly which image you have chosen. The photos you display must not be deceptive, false or misleading any way that infringes on third party intellectual property. You must also not encourage of incentivize other fellow users, friends or business associates to display the same cover image as yours on personal Timelines.<\/p>\r\n<p>To sum up we are extremely excited about the latest Facebook feature release this week. They constantly deliver new services that are amazing and incredibly innovative to the market place.<\/p>\r\n<p>Here at Northplanet we are commited to provide you with the latest information on the hottest online topics around, to keep you ahead in the game. We would love to hear some feedback from you on the brand new Facebook 'Timeline for Brands' release and invite you to visit our very own <a href=\"https:\/\/www.facebook.com\/northplanet\">Northplanet Facebook Timline page by clicking here.<\/a><\/p>", "tags":"facebook, new fan page", "views":"463", "categorie_id":"2", "post_url":"facebooks-new-fan-page-learn-how-to-use-features" },{ "blog_id":"2", "post_date":"Mon, 23 January 2012", "post_title":"Northplanet Engages New Talent!", "article_img":"http:\/\/www.socialnewsoffice.com\/uploads\/1263.jpg", "post_content":"<p>Big piece of news for the start of 2012 is…… I have landed a full time role in a leading Web Design and Development agency based in Greater Manchester. After a successful interview on New Years Eve, I had another reason to celebrate bringing in the New Year!!<\/p>\r\n<p>I was first attracted to Northplanet when I came across there website when searching for jobs online. I was impressed not only by the standard of web work but the direction the company where going in. Growing year by year and providing exceptional web solutions for a number of businesses spread across the UK.<\/p>\r\n<p>I contacted them instantly and have done some freelance work a few times in the last year for Directors Danny and Mike and was able to build up a strong working relationship that helped me land the interview at the end of the year.<\/p>\r\n<p>I begin my career at Northplanet next week and will post all offers\/promotions and deals on here in the nearfuture.<\/p>\r\n<p>Time to sign off and prepare for my new career!!<\/p>", "tags":"engages new talent, new staff, northplanet staff, christian thomas mizon", "views":"271", "categorie_id":"1", "post_url":"northplanet-engages-new-talent" }] here is my code that does this Code: [Select] if (mysqli_num_rows($r) > 0) { // Available. while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $results[] = array( 'blog_id' => ($row['ID']), 'post_date' => ($row['pd']), 'post_title' => (html_entity_decode($row['post_title'], ENT_QUOTES)), 'article_img' => ('http://www.socialnewsoffice.com/uploads/'.$row['article_img']), 'post_content' => ($row['post_content']), 'tags' => ($row['tags']), 'views' => ($row['views']), 'categorie_id' => ($row['categorie_id']), 'post_url' => ($row['post_url'])); } echo $json = Pretty_JSON(json_encode($results)); } i can access the json by using foreach($blog_posts as $post) { however what i need to do is add a value to the json like pages => 2 how could i do this? Hey guys I am Posting data over to a server file in Json and I need to know how I can add to the XML file. here is both codes.
function validate() { $xml = simplexml_load_file("stock.xml"); $sxe = new SimpleXMLElement($xml->asXML()); for($i = 1; $i < 801; $i++) { $newItem->addChild("name" , "null"); } $sxe->asXML("stock.xml"); echo $sxe->asXML(); $response = $_POST; $response["items"] = "Test output"; $response["description"] = "test 42 "; $response["json"] = json_encode($response); echo json_encode($response); }The red text is what I want this json script to do. Do I have to return back to my form to add to the XML file? Can json add to a xml file on its own? Thanks for your time! have a good day! Hi, I have two select boxes on my site like this: Language - Level and the user can keep adding more sets of select boxes. I need the data posted to be JSON encoded like this: {"LANG1":["German","Beginner"],"LANG2":["Polish","Advanced"]} etc How can i make this happen? how can i also output $pages number into the json as well so i can use it for jquery Code: [Select] <?php // Start Buffer ob_start(); // Load Settings require '../../includes/config.inc.php'; // Require the database connection: require(MYSQL); // Number of records to show per page: $display = 6; // Determine how many pages there are... if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined. $pages = $_GET['p']; }else{ // Need to determine. // Default Query $count_q = "SELECT COUNT(id) FROM deals"; // Count the number of records: $r = @mysqli_query ($dbc, $count_q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Make the query: $q = "SELECT id, url, views, deal_img, title, savings, DATE_FORMAT(expiry, '%a, %d %b %Y') AS expr FROM deals ORDER BY created_on DESC LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // Run the query. if (mysqli_num_rows($r) > 0) { // Available. /* create one master array of the records */ $offers = array(); while ($offer = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $offers[] = array("id" => $offer["id"], "url" => BASE_APP_URL.'offer/'.$offer["url"].'/', "views" => $offer["views"], "image" => BASE_URL.'niftyuk-deal/'.$offer["deal_img"], "title" => $offer["title"], "savings" => $offer["savings"], "expr" => $offer["expr"]); } // End of WHILE loop. } /* output in necessary format */ header('Content-type: application/json'); echo json_encode($offers); ?> Okay so i know this is going to sound really stupid i just got out of school and now im in the real world here is the problem I dont know very much about how to work with JSON via PHP all i am trying to do is have the Script read data into an array from some text boxes then from the array into a JSON file the reading and the listing is all fine and dandy but only if i want the entire file how do i read data from a JSON file and only have it display data according to what i want so for example if i wanted to return data that matched an ID like you would do in MySQL like this ("SELECT * FROM catagories WHERE ID = '$id'") so how do i do that without a Database using a JSON File as a source for the data My script is not acting like it should. I believe its because of the recent change in the api, (the new error array)? Before there was only one.... <?php $gamertag = 'l RaH l'; $url = "http://api.xboxleaders.com/user_api.php?gamertag=".str_replace(' ', '%20', $gamertag); $output = file_get_contents($url); // try to convert the response into a PHP object $obj = json_decode($output); if(!is_object($obj)) die("Error parsing JSON response\n"); //define variables $avatar = ($obj->user->avatar); $gold = ($obj->user->gold); print $avatar; print $gold; ?> if you print_r $object; it displays this {"error":{"code":200,"desc":"OK"}},{"user":{"gold":1,"gamertag":"l RaH l","avatar":"http:\/\/avatar.xboxlive.com\/avatar\/l%20RaH%20l\/avatarpic-l.png","gamerscore":12508,"reputation":20},"recent_games":[{"recent_game":{"title":"Halo: Reach","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1297287259&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/ih\/ew\/0Wdsb2JhbA9ECgR8GgMfVlohL2ljb24vMC84MDAwIAAAAAAAAP6fF5U=.jpg"}},{"recent_game":{"title":"Halo 3","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1297287142&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/Us\/3e\/1Wdsb2JhbA9ECgR8GgMfWSpVL2ljb24vMC84MDAwIAAAAAAAAPrxzU0=.jpg"}},{"recent_game":{"title":"AC Brotherhood","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504989&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/oK\/tp\/1Wdsb2JhbA9ECgUNGgMfVlonL2ljb24vMC84MDAwIAAAAAAAAPpGq78=.jpg"}},{"recent_game":{"title":"Fighters Uncaged","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504974&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/v+\/Au\/0Wdsb2JhbA9ECgUNGgMfVlsmL2ljb24vMC84MDAwIAAAAAAAAP4B4KA=.jpg"}},{"recent_game":{"title":"Assassin's Creed","link":"http:\/\/gamercard.xbox.com\/en-US\/GameCenter\/Achievements?titleId=1431504852&compareTo=l%20RaH%20l","image":"http:\/\/tiles.xbox.com\/tiles\/L3\/mu\/0Wdsb2JhbA9ECgUNGgMfWStXL2ljb24vMC84MDAwIAAAAAAAAP6BeTA=.jpg"}}]} I have some PHP which sends some user provided data to the client:
<?php header('Content-type: application/json'); $data=array( array('id'=>10,'firstname'=>'John','lastname'=>'Doe'), array('id'=>14,'firstname'=>'Jane','lastname'=>'Doe'), array('id'=>19,'firstname'=>'XSS!','lastname'=>'XSS!'), ); echo(json_encode($data)); ?>The client then displays the data: $.getJSON('getJSON.php', { something: 123 }, function(list) { var string = ''; for (var i in list) { string += '<li>< a href = "index.php?id=' + list[i]['id'] + '">' + list[i]['firstname'] + '</a></li>'; } $("#MyElem").html(string); });Does this represent any XSS risk? If so, how do I prevent it? Hello, I can't get a json call to work in my php... Hope some one can see where I am going wrong and push me in the right direction. I have 3 values I am trying to send from the php file to the html. The output looks as if it should work, but is does not... So here is the php variable that does give me a result, but I have no idea why it does not show in the div. <?php $choice = (isset($_POST['choice'])) ? date("Y-m-d",strtotime($_POST['choice'])) : date("Y-m-d"); $con = mysql_connect("localhost","root","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT sum(power/1000) AS choice FROM feed WHERE date = '".$choice."' group by date"; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); $dayPowerP = array( $row['choice']); ?> <?php $choice = (isset($_POST['choice'])) ? date("m",strtotime($_POST['choice'])) : date("m"); $con = mysql_connect("localhost","root","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT sum(power/1000) AS choice FROM feed WHERE month(date) = '".$choice."'"; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); $monthPowerP = array($row['choice']); ?> <?php $choice = (isset($_POST['choice'])) ? date("Y",strtotime($_POST['choice'])) : date("Y"); $con = mysql_connect("localhost","root","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $sql = "SELECT sum(power/1000) AS choice FROM feed WHERE year(date) = '".$choice."'"; $res = mysql_query($sql) or die('sql='.$sql."\n".mysql_error()); $row = mysql_fetch_assoc($res); $yearPowerP = array( $row['choice']); ?> <?php $outarr['dayPowerP'] = $dayPowerP; $outarr['monthPowerP'] = $monthPowerP; $outarr['yearPowerP'] = $yearPowerP; echo json_encode($outarr); ?> Now there are no errors, and this is what the output is so I would assume it should work as the right values are there and the right id..... Code: [Select] {"dayPowerP":["12.7240"],"monthPowerP":["145.0460"],"yearPowerP":["941.0370"]} I do not understand. Now the Jquery should be working as well... the ajax should be sending the post with json to carry the key data to make a clear result from the php and json should be doing it's job in the php file and the Jquery is do basic to have any issues, so that leaves my focus on the PHP at this time, but I do not see a proplem. Code: [Select] $(document).ready(function () { $('#datepicker').datepicker({maxDate: 0, dateFormat: 'yy-mm-dd', onSelect: function(dateText) { var myDate = $(this).datepicker('getDate'); $('#apDiv1').html($.datepicker.formatDate('DD, d', myDate)); $('#apDiv5').html($.datepicker.formatDate('MM', myDate)); $('#apDiv7').html($.datepicker.formatDate('yy', myDate)); $.ajax({ type: "POST", url: "clickdates.php", data: {choice: dateText}, dataType: "json", success: function(json_data) { $('#apDiv2').html(json_data['dayPowerP']); $('#apDiv6').html(json_data['monthPowerP']); $('#apDiv8').html(json_data['yearPowerP']); } }) }}); }); The one thing that is odd. When I use 3 different php files, it works perfect, but that is not using json. Now that I am using json to return 1 call from the php, I am lost at this point, does anyone see what I can't... Thanks, Alan im trying to access code in Code: [Select] array(1) { [0]=> object(stdClass)#4 (1) { ["error"]=> array(1) { [0]=> object(stdClass)#5 (2) { ["message"]=> string(33) "no results found (error code 458)" ["code"]=> string(3) "458" } } } } ive tryed echo $blog_posts[0]->error->code; but all i get is Notice: Trying to get property of non-object in /home/sites/inspiredanceacademy.com/public_html/sno-blog-test/lib/social_news_office.php on line 173 Hello everyone, I'm new here. Amazing forum, I found some help in the past by searching google.
Now I am looking for some help with the following code, I use this code to grab a JSON Feed and list the items in my page, this code works fine to get all the items, but I need to limit the number of items, otherwise It will load more than 500 items in my page and never stop loading.
Is there a way to limit the number of items grabbed from the JSON Feed?
Let's say, list 50 items in page 1, another 50 in page 2 and so on?
<?php $data = file_get_contents('http://json-url.com/type=json'); $decode = json_decode($data, true); foreach($decode as $d) { if($d['status'] == true){ echo '<div class="div">'; echo '<a href="'.$d['item_url'].'">'; echo '<img src="'.$d['item_image']['jpeg_thumbnail'].'" />'; echo '<span>'.$d['item_name'].'</span>'; echo '</a>'; echo '</div>'; } } ?>Thanks! Hi there, Hoping some one can help. I am new to using PDO and i am trying to get data from my db to json I can get the data down to my $result so i know that part is working, my issue is with encoding it to json, if i pull a single record then it works if i pull all records then it doesn't, an i am not sure why $result = $page->read($_GET['pageid']); //check for data if ($result) { //page array $page_arr['pages'] = array(); while ($row =$result->fetch(PDO::FETCH_ASSOC)) { extract($row); $page_item = array( 'id'=> $id, 'title' => $title, 'pageid' => $pageid, 'pagecontent' =>html_entity_decode($pagecontent), 'mdkeywords' => $mdkeywords, 'description' =>$description, 'date_added' =>$date_added, 'hasAudio' => $hasAudio, 'excludeSearch' =>$excludeSearch ); //push to data array_push($page_arr['pages'], $page_item); } //print_r($page_arr['pages']); //If i enable this then i can see all the data //turn to json echo json_encode($page_arr['pages'], JSON_FORCE_OBJECT); //This is where my page is blank. } } else { echo json_encode(array('message'=>'nothing here!.')); }
|