Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert php string data to Json object using Jquery
    primarykey
    data
    text
    <p>I need to get some Json data from PHP to jquery.</p> <p>I need the below format in a javascript method.</p> <pre><code>function returnJson() { return { events: [ { "id": 1, "start": new Date(2013, 4, 26, 12), "end": new Date(2013, 4, 26, 13, 30), "title": "Lunch with Mike" }, { "id": 2, "start": new Date(2013, 4, 27, 14), "end": new Date(2013,4, 27, 14, 45), "title": "Dev Meeting" }] }; } </code></pre> <p>For this I am doing the below things in javascript:</p> <pre><code>function returnJson() { var eventResult = $.getJSON("../PHP/PhpAction.php?f=fetchCalendarEvent"); return eventResult; } </code></pre> <p>in php:</p> <pre><code> function fetchCalendarEvent() { $tablename = "tb_calendar"; $sql = "SELECT eventId,userId,enentName,eventText,EXTRACT(YEAR FROM startTime) AS startyear,EXTRACT(MONTH FROM startTime) AS startMonth,EXTRACT(DAY FROM startTime) AS startDay,EXTRACT(HOUR FROM startTime) AS startHour,EXTRACT(MINUTE FROM startTime) AS startMin,EXTRACT(YEAR FROM endTime) AS endyear,EXTRACT(MONTH FROM endTime) AS endMonth,EXTRACT(DAY FROM endTime) AS endDay,EXTRACT(HOUR FROM endTime) AS e`enter code here`ndHour,EXTRACT(MINUTE FROM endTime) AS endMin FROM ".$tablename." WHERE userId='".$_SESSION['userid']."' AND isActive=1"; $q = mysql_query($sql); $i=1; $eventData="{events: ["; if (!mysql_num_rows($q)) { echo 'No records found'; } else { while ($row = mysql_fetch_assoc($q)) { $eventData.="{'id':".$row['eventId'].","; $eventData.="'end': new Date(".$row['startyear'].",".$row['startMonth'].",".$row['startDay']."," .$row['startHour'].",".$row['startMin']."),"; $eventData.="'start': new Date(".$row['endyear'].",".$row['endMonth'].",".$row['endDay'].",".$row['endHour'].",".$row['endMin']."),"; $eventData.="'title':'".$row['enentName']."'},"; $i++; } } $eventData= rtrim($eventData, ","); $eventData.="]}"; echo json_decode($eventData); } </code></pre> <p>I check in firebug the php method is returning data like:</p> <pre><code>{ events: [ { 'id': 2, 'end': new Date(2013, 4, 27, 18, 38), 'start': new Date(2013, 4, 27, 18, 38), 'title': 'test' }, { 'id': 3, 'end': new Date(2013, 4, 23, 11, 0), 'start': new Date(2013, 4, 23, 14, 15), 'title': 'testing23' } ] } </code></pre> <p>Can any one please help me. I am new in php. Any help would be highly appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload