RP Posted May 11, 2007 Share Posted May 11, 2007 So i was working on this script last night and had it working fairly well, i came back in the morning and made some alts, only to have my computer crash and as per usual i had saved a unworking version and couldnt revert. My last version of the page was at 4pm, however its not working. It is constantly giving me an "Fatal error: Call to undefined function: json_encode() on line 64". Last night it was delivering me a Json array like it should be. <?php $code = "user 2"; if (!$db = mysql_connect($host, $user, $pass)) { echo 'Could not connect to mysql'; exit; } if (!mysql_select_db($dbname, $db)) { echo 'Could not select database'; exit; } $query = "SELECT * FROM graph WHERE username = '$code'"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $value0=mysql_result($result,$i,"value0"); $value1=mysql_result($result,$i,"value1"); $value2=mysql_result($result,$i,"value2"); $value3=mysql_result($result,$i,"value3"); $value4=mysql_result($result,$i,"value4"); $i++; } $dataset = array( 'ds1'=>array( array(0,$value0), array(1,$value1), array(2,$value1), array(3,$value3), array(4,$value4) ) ); $options = array( 'xTicks'=>array( array('v'=>0,'label'=>'Mon'), array('v'=>1,'label'=>'Tue'), array('v'=>2,'label'=>'Wed'), array('v'=>3,'label'=>'Thur'), array('v'=>4,'label'=>'Fri') ) ); $return = array( 'dataset'=>$dataset, 'options'=>$options ); header("Content-type: text/json"); echo json_encode($return); ?> Doing some reaserach i tried using the default php example for json_encode(); <?php $arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr); ?> this gave me a fatal error as well. Nothing has changed on my server at all. So i ask you PhpFreaks.com, WTF is going on? and furthermore, how do i fix it? Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/ Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Share Posted May 11, 2007 Maybe try something like this? $return = json_encode($return); echo "$return"; Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-250304 Share on other sites More sharing options...
RP Posted May 11, 2007 Author Share Posted May 11, 2007 no dice : ( still getting a fatal error on line 64 - $return = json_encode($return); Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-250306 Share on other sites More sharing options...
chronister Posted May 11, 2007 Share Posted May 11, 2007 If it is telling you Call To Undefined Function, then that means that the function is not defined. Where is this json_encode() function actually set at? You need to ensure that if it is in an external file like an include, that the include is being well ... included. anytime you get a Call To Undefined Function, that means that the function is not available to that part of the script. If xyz(); is defined in included_stuff.php this would return an error xyz('pass_var'); include('included_stuff.php'); Here I am calling the function before it is available in the script as it is defined in included_stuff.php Find the function and make sure it's defined before calling it nate Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-250350 Share on other sites More sharing options...
RP Posted May 13, 2007 Author Share Posted May 13, 2007 The Dataset links into this piece of code: <script> Object.extend(Plotr.LineChart.prototype,{ getRemoteDatasetAndRender: function(url) { var xhr_options = { method: 'get' } xhr_options.onComplete = function(xhr) { var json = eval('('+xhr.responseText+')'); this.addDataset(json.dataset); this.setOptions(Object.extend(this.options,json.options)); this.render(); }.bind(this); new Ajax.Request(url,xhr_options); } }); //we won't include the axis details in the options, // as the remote call will provide them var options = { padding: {left: 30, right: 0, top: 10, bottom: 30}, backgroundColor: '#dbdbdb', colorScheme: 'red' }; var line = new Plotr.LineChart('plotr',options); //then just pass the URL to the function line.getRemoteDatasetAndRender('dataset4pm.php'); </script> Would this undefiend function apply even for the default example i listed in my first post? Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252334 Share on other sites More sharing options...
RP Posted May 14, 2007 Author Share Posted May 14, 2007 bump becasue i still cant make this work and i dont have much more hair to pull out. Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252465 Share on other sites More sharing options...
chronister Posted May 14, 2007 Share Posted May 14, 2007 I did not realize that json_encode() is a built in php function. Looks like the PECL extension has to be installed. http://www.php.net/manual/en/ref.json.php If your getting call to undefined, then that means that PECL extensions are not installed. Gonna have to install that before it will work. Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252482 Share on other sites More sharing options...
RP Posted May 14, 2007 Author Share Posted May 14, 2007 if this was the problem how was it generating strings before i lost my working version? Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252495 Share on other sites More sharing options...
chronister Posted May 14, 2007 Share Posted May 14, 2007 did you move servers or make changes to the configuration? When I tried to use it I get call to undefined function. I know that I don't have the PECL extension installed. Do a phpinfo() and see if they are installed on your system. Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252505 Share on other sites More sharing options...
RP Posted May 14, 2007 Author Share Posted May 14, 2007 I havent switched server or touched anything, i almost wish i had so i could find the problem. Running phpinfo() and doing a find for json came up with only one result under Configure Command; '--with-zip=/usr' '--with-json' '--with-pear' '--enable-utf8' '--enable-track-vars' '--enable-trans-sid' Im not sure exactly what this means but i do know that i was perviously able to watch firebug display my Json string and in turn watch it build my graph. Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252514 Share on other sites More sharing options...
chronister Posted May 14, 2007 Share Posted May 14, 2007 hmmmmm sorry man, I am out of Ideas. Does PHPINFO show anything about the PECL extensions? Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252525 Share on other sites More sharing options...
RP Posted May 14, 2007 Author Share Posted May 14, 2007 not a thing :\ Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252529 Share on other sites More sharing options...
chronister Posted May 14, 2007 Share Posted May 14, 2007 Then I would start there. From what I saw in the manual, the PECL extension needs to be installed. But I am just grasping at straws here. Quote Link to comment https://forums.phpfreaks.com/topic/50893-json_encode-halp/#findComment-252668 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.