PHP/Json Not working
Results 1 to 4 of 4

Thread: PHP/Json Not working

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    2

    Cool PHP/Json Not working

    Hello everybody,

    I have a little code for you awesome expert PHP programmers out there. I have no idea what I'm doing...kind of.

    Basically, what's wrong is that the files I am using for the website are using a version of PHP different from that of the web host itself - I think. The problem is that Open Flash Chart does not display anything. I think what's going wrong is somewhat related to

    "open flash chart
    json parse error [syntax error] error at character 0, line 1:
    0: <br>"

    But I'm not sure.

    I have some code here. This is only a small part of the code in the PHP file. I think the problem lies somewhere in here...

    Code:
    public function getpilotsjson()
    	{
    		$page = $this->get->page; // get the requested page 
    		$limit = $this->get->rows; // get how many rows we want to have into the grid 
    		$sidx = $this->get->sidx; // get index row - i.e. user click to sort 
    		$sord = $this->get->sord; // get the direction 
    		if(!$sidx) $sidx =1;
    		
    		/* Do the search using jqGrid */
    		$where = array();
    		if($this->get->_search == 'true') 
    		{
    			$searchstr = jqgrid::strip($this->get->filters);
    			$where_string = jqgrid::constructWhere($searchstr);
    			
    			# Append to our search, add 1=1 since it comes with AND
    			#	from above
    			$where[] = "1=1 {$where_string}";
    		}
    		
    		Config::Set('PILOT_ORDER_BY', "{$sidx} {$sord}");
    		
    		# Do a search without the limits so we can find how many records
    		$count = count(PilotData::findPilots($where));
    		
    		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)
    		if ($start < 0) 
    		{
    			$start = 0;
    		}
    		
    		# And finally do a search with the limits
    		$allpilots = PilotData::findPilots($where, $limit, $start);
    		if(!$allpilots)
    		{
    			$allpilots = array();
    		}
    		
    		# Form the json header
    		$json = array(
    			'page' => $page,
    			'total' => $total_pages,
    			'records' => $count,
    			'rows' => array()
    		);
    		
    		# Add each row to the above array
    		foreach($allpilots as $row)
    		{
    			$status = ($row->retired==0) ? 'Active' : 'Retired';
    			$location = '<img src="'.Countries::getCountryImage($row->location).'" alt="'.$row->location.'" />';
    			$edit = '<a href="'.adminurl('/pilotadmin/viewpilots?action=viewoptions&pilotid='.$row->pilotid).'">Edit</a>';
    			
    			$tmp = array(
    				'id' => $row->id,
    				'cell' => array(
    					# Each column, in order
    					$row->id,
    					$row->firstname,
    					$row->lastname,
    					$row->email,
    					$location,
    					$status,
    					$row->rank,
    					$row->totalflights,
    					$row->totalhours,
    					$row->lastip,
    					$edit,
    				),
    			);
    			
    			$json['rows'][] = $tmp;
    		}
    		
    		header("Content-type: text/x-json");
    		echo json_encode($json);
    	}

    --------------------------


    Thanks in advance for all help!

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,844
    Quote Originally Posted by webmaster11
    Code:
    "open flash chart
    json parse error [syntax error] error at character 0, line 1:
    0: <br>"
    Perhaps an error message is being generated and sent instead of JSON. You may want to look with your browser's network activity monitor to see exactly what it is receiving; if it's an error message, it should give you a better idea of what is failing.

    Quote Originally Posted by webmaster11
    Basically, what's wrong is that the files I am using for the website are using a version of PHP different from that of the web host itself
    Which versions are they? If the host is stuck on something earlier than 5.2 then that would explain it because that's when json_encode was added to PHP.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    The host is on 5.4 and the files are on 5.3 I believe. Thanks for your reply. I'm kind of a newbie, so I don't really know how to look with my browser's network activity monitor.

  4. #4
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,844
    Quote Originally Posted by webmaster11
    I'm kind of a newbie, so I don't really know how to look with my browser's network activity monitor.
    It depends on your browser.
    Chrome: https://developers.google.com/chrome...s/docs/network
    Firefox: https://developer.mozilla.org/en-US/...etwork_Monitor
    IE: I couldn't find an official page, so Google would have to do... http://blogs.msdn.com/b/ie/archive/2...twork-tab.aspx
    Opera: http://www.opera.com/dragonfly/

    Another thing you can do is make the request manually by entering the URL in the browser's address bar and reading what comes back.
    Last edited by Weedpacket; 04-25-2014 at 10:48 PM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •