>From a design perspective, I prefer to open database connections only when 
strictly necessary, and close them when I'm done using them.  You could, I 
believe, start a session on your index page and save your database 
connection in a $_SESSION variable (then retrieve the database connection 
from $_SESSION in the viewDataTable.php script), but this could result in 
an arbitrary number of database connections hanging open on your server 
until the sessions are closed or timed out.  I think you are asking for 
problems at that point.

On Saturday, August 17, 2013 7:37:57 AM UTC-4, Razee Hussein-Jamal wrote:
>
> I found the problem,
>
> My database connection is established on a seperate php file which is 
> included into index.php, form index.php file the system navigates to 
> different pages for example the viewDataTable.php which has the ajax script 
> that calls the php code for query data from database. However even if the 
> database connection is established globally to all the pages, the 
> connection is lost once the ajax script runs.
>
> So I had to include it once again, but wonder if there are any other ways 
> to solve this?
>
> Thank you!
>
>
> On 17 August 2013 11:50, Razee Hussein-Jamal <[email protected]<javascript:>
> > wrote:
>
>> I tried to run the PHP code directly from the URL it worked fine, it 
>> returned the JSON string correctly but once again I tried to call this PHP 
>> code from AJAX and the row returned to null, as it's not entering the while 
>> loop as I mentioned earlier. The domain is the same of the AJAX script and 
>> data source script is the same....
>> This is driving me crazy! 
>>
>> If you could please look at my code maybe I am missing sth, 
>> http://stackoverflow.com/questions/18274356/display-google-chart-with-json-and-php
>>
>>
>>
>>
>> On 17 August 2013 04:03, asgallant <[email protected] 
>> <javascript:>>wrote:
>>
>>> I don't think that would change anything.  Calling the PHP script from 
>>> an AJAX call also shouldn't return any different results.  If it works 
>>> right when you visit the URL directly from your browser, it should work 
>>> when you pull it from AJAX.  The only time you might expect a different 
>>> result is if the domain of the HTML file making the AJAX call is different 
>>> from the domain of the data source script.
>>>
>>>
>>> On Friday, August 16, 2013 4:23:55 PM UTC-4, Razee Hussein-Jamal wrote:
>>>
>>>> I should also mention I have changed this line of code : 
>>>>
>>>> $selectQuery = 'SELECT * FROM competitive_daily_volume';
>>>> $result = mysql_query($selectQuery);
>>>> $rows = array();
>>>> if($result){
>>>>     
>>>>     while($row = mysql_fetch_assoc($result)){..**........} 
>>>> }
>>>>
>>>> To this:
>>>>
>>>> $selectQuery = 'SELECT * FROM competitive_daily_volume';
>>>>
>>>> $rows = array();
>>>> if($result = mysql_query($selectQuery)){
>>>>     
>>>>     while($row = mysql_fetch_array($result)){ ........}
>>>>
>>>> }
>>>>
>>>> But the rows is null, I don't think it enters the while loop when this 
>>>> file has been called from the JavaScript. 
>>>>
>>>> Would appreciate any kind of help, thank you in advance 
>>>> Sent from my iPhone
>>>>
>>>> On 16 aug 2013, at 23:17, Razee <[email protected]> wrote:
>>>>
>>>> It seems that it doesn't enter the while loop when this file is called 
>>>> from the JavaScript. Could it be that the 
>>>>
>>>> while($row = mysql_fetch_assoc($result)) 
>>>>>
>>>>
>>>> Blocks the Ajax  when it's called, the rows on the Json string is null 
>>>> but cols is not and its correct when it's been passed. 
>>>>
>>>> I really need help with this part I have been working on it for days, 
>>>> there is a mistake which I can't find. 
>>>>
>>>>
>>>> On 16 aug 2013, at 17:43, asgallant <[email protected]> wrote:
>>>>
>>>> Your PHP code looks fine.  Navigate to that script in a browser and see 
>>>> if it is outputting a JSON string there.
>>>>
>>>> On Friday, August 16, 2013 8:37:56 AM UTC-4, Razee Hussein-Jamal wrote:
>>>>>
>>>>> Thank you for your help, this is the code I have inside the json.php 
>>>>> the connection to database is done in a separate file, I don't get the 
>>>>> JSON 
>>>>> objects when I call this file in the ajax script.
>>>>>
>>>>> <?php
>>>>>
>>>>> $selectQuery = 'SELECT * FROM competitive_daily_volume';
>>>>> $result = mysql_query($selectQuery);
>>>>> $rows = array();
>>>>> if($result){
>>>>>     
>>>>>     while($row = mysql_fetch_assoc($result)){
>>>>>         $temp =  array();
>>>>>         $temp[] = array("v"=> $row['Date']);
>>>>>         $temp[] = array("v"=> $row['UserId']);
>>>>>         $temp[] = array("v"=> $row['CementBrand']);
>>>>>         $temp[] = array("v"=> $row['VolumeBGLP']);
>>>>>         $temp[] = array("v"=> $row['Type']);
>>>>>         
>>>>>         $rows[] = array("c"=> $temp);
>>>>>
>>>>>     }
>>>>>
>>>>> }
>>>>>
>>>>> $table = array();
>>>>> $table['cols'] = array(
>>>>>     array("id"=>"A","label"=>"**Date","type"=>"string"),
>>>>>     array("id"=>"B","label"=>"**User","type"=>"string"),
>>>>>     array("id"=>"C","label"=>"**Cement Brand","type"=>"string"),
>>>>>     array("id"=>"D","label"=>"**Volume","type"=>"string"),
>>>>>     array("id"=>"E","label"=>"**Type","type"=>"string")
>>>>> );
>>>>>   
>>>>> $table['rows'] = $rows;
>>>>> $jsonObj = json_encode($table);
>>>>>
>>>>> echo $jsonObj;
>>>>>
>>>>> ?>
>>>>>
>>>>>
>>>>>
>>>>> On 12 August 2013 23:24, asgallant <[email protected]> wrote:
>>>>>
>>>>>> I don't get that error when I use your JSON: 
>>>>>> http://jsfiddle.net/asgallant/**R8tA9/<http://jsfiddle.net/asgallant/R8tA9/>.
>>>>>>   
>>>>>> Can you post an example script (preferably on jsfiddle, you can use the 
>>>>>> example I linked to as a starting point) that replicates the issue?
>>>>>>
>>>>>>
>>>>>> On Monday, August 12, 2013 3:19:07 PM UTC-4, Razee Hussein-Jamal 
>>>>>> wrote:
>>>>>>
>>>>>>>
>>>>>>>  I am trying to view my JSON string I receive from a database and 
>>>>>>> view it in google tables, however I receive this error: Invalid 
>>>>>>> JSON string: error: 1046
>>>>>>>
>>>>>>>  In viewTable.php a part of the script is :
>>>>>>>
>>>>>>>   function drawVisualization() {
>>>>>>>       
>>>>>>>         var jsonData = $.ajax({
>>>>>>>           url: "json.php", // make this url point to the data file
>>>>>>>           dataType: "json",
>>>>>>>           async: false
>>>>>>>         }).responseText;
>>>>>>>     var data = new google.visualization.**DataTable**(jsonData); 
>>>>>>>    
>>>>>>>       visualization = new google.visualization.Table(**doc**
>>>>>>> ument.getElementById('**table'))**;
>>>>>>>       visualization.draw(data, null);
>>>>>>>              
>>>>>>>     }
>>>>>>>
>>>>>>> in json.php file : I query data from database and encode it to JSON 
>>>>>>> string which I then echo $jsonString,
>>>>>>>
>>>>>>> An example of JSON string output :
>>>>>>>
>>>>>>>
>>>>>>> {"cols":
>>>>>>> [{"id":"A","label":"Date","**typ**e":"string"},{"id":"B","**label"**
>>>>>>> :"User","type":"string"}**,{"id"**:"C","label":"Cement 
>>>>>>> Brand","type":"string"},{"id":****"D","label":"Volume","type":"**s**
>>>>>>> tring"},{"id":"E","label":"**Typ**e","type":"string"}],
>>>>>>>
>>>>>>> "rows":
>>>>>>> [{"c":[{"v":"08-06-2013"},{"v"****:"[email protected]"},{"v":"**Mu**
>>>>>>> thana"},{"v":"27"},{"v":"**Local Plant"}]}]
>>>>>>>
>>>>>>> } 
>>>>>>>
>>>>>>>
>>>>>>> I would really appreciate any help with this problem as I can't find 
>>>>>>> the reason for this invalid JSON string as it seems to be correct. 
>>>>>>> Thank you
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>  -- 
>>>>>> You received this message because you are subscribed to a topic in 
>>>>>> the Google Groups "Google Visualization API" group.
>>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>>>>> topic/google-visualization-**api/_4eMVS6Hdnk/unsubscribe<https://groups.google.com/d/topic/google-visualization-api/_4eMVS6Hdnk/unsubscribe>
>>>>>> .
>>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>>> google-visualization-api+**[email protected].
>>>>>> To post to this group, send email to google-visua...@googlegroups.**
>>>>>> com.
>>>>>> Visit this group at http://groups.google.com/**
>>>>>> group/google-visualization-api<http://groups.google.com/group/google-visualization-api>
>>>>>> **.
>>>>>> For more options, visit 
>>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>>>> .
>>>>>>  
>>>>>>  
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -- 
>>>>> Razee Hussein-Jamal
>>>>> Masters in Embedded Systems,
>>>>> Department of Information Technology,
>>>>> Uppsala University - Sweden
>>>>> Mobile Phone : +46764158553 (Sweden) , +9647701524721 (N.Iraq), 
>>>>> +905058622477 (Turkey)
>>>>>
>>>>>   -- 
>>>> You received this message because you are subscribed to a topic in the 
>>>> Google Groups "Google Visualization API" group.
>>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>>> topic/google-visualization-**api/_4eMVS6Hdnk/unsubscribe<https://groups.google.com/d/topic/google-visualization-api/_4eMVS6Hdnk/unsubscribe>
>>>> .
>>>> To unsubscribe from this group and all its topics, send an email to 
>>>> google-visualization-api+**[email protected].
>>>> To post to this group, send email to google-visua...@**googlegroups.com
>>>> .
>>>> Visit this group at http://groups.google.com/**
>>>> group/google-visualization-api<http://groups.google.com/group/google-visualization-api>
>>>> **.
>>>> For more options, visit 
>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>> .
>>>>
>>>>  -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Google Visualization API" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/google-visualization-api/_4eMVS6Hdnk/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] <javascript:>.
>>> To post to this group, send email to 
>>> [email protected]<javascript:>
>>> .
>>> Visit this group at 
>>> http://groups.google.com/group/google-visualization-api.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> -- 
>> Razee Hussein-Jamal
>> Masters in Embedded Systems,
>> Department of Information Technology,
>> Uppsala University - Sweden
>> Mobile Phone : +46764158553 (Sweden) , +9647701524721 (N.Iraq), 
>> +905058622477 (Turkey)
>>
>>  
>
>
> -- 
> Razee Hussein-Jamal
> Masters in Embedded Systems,
> Department of Information Technology,
> Uppsala University - Sweden
> Mobile Phone : +46764158553 (Sweden) , +9647701524721 (N.Iraq), 
> +905058622477 (Turkey)
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to