Hello..this is my first attempt to ask a question on this forum..I am trying to be as descriptive as possible
what I have is select option in 'chart.php' page and once I select the value,it's passed to another 'getvalue.php' page using get. this 'getvalue.php' page will connect and run sql query with the value I sent and make table from the result and send it back using AJAX callback..it works fine for this concept so far.
Now, I am trying something else. I am using google charts to visualize the data. So the thing is I run php code from 'chart.php' page where I manually enter the value for the query to take in and create a result for associative array. This array is linked to a variable myurl[]. Afterwards, in this same page 'chart.php'..I am in my Javascript calling this will variable because there is an option for arraytoDatatable in google charts. once all of this is done, the chart is displayed and everything is fine and happy.
Now, what I want to do is select a value from the options and send that value in the same 'chart.php' page and run the query and update the google charts...so far I haven't been able to figure out why can't it send the value to the same page.
I am not even sure if php can refer to its own self and call the value. Here's the code:
<html>
<form id="myform" method="GET" action="<?php echo $_SERVER['$PHP_SELF'];?>">
Select a orbital period (in days)
<select id="sf" name="star">
<option value="0">0</option>
<option value="0.5">0.5</option>
<option value="10">10</option>
<option value="100">100</option>
<option value="365">365</option>
</select>
</form>
<?php
$o = intval($_GET['star']);
/*$o = '10';*/
echo "$o<br>";
$con = mysqli_connect('localhost','username','password');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,'mydatabase');
$sql="SELECT * FROM exoplanetdb WHERE pl_orbper >= '".$o."' ";
$result = mysqli_query($con,$sql);
$myurl[] = "['Mass','Mass,Radius(J)']";
while($row = mysqli_fetch_assoc($result))
{
$mass=$row['pl_masse'];
$radj=$row['pl_radj'];
$myurl[] = "[".$mass.",".$radj."]";
}
mysqli_close($con);
?>
<!--make the chart-->
<script src="https://www.google.com/jsapi"></script>
<script>
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
<?php echo(implode(",",$myurl));?>
]);
var options = {
selectionMode: 'multiple',
title: 'Mass vs Size(times Jupiter radius)',
hAxis: {title:'Mass(times Earths)'},
vAxis: {title:'Radius(times Jupiter)'}
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</html>
if something is unclear..plz ask me..I will try to explain..Thank you for your time