Jump to content

pass select value to same php page


supercone

Recommended Posts

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

Link to comment
Share on other sites

  • 4 weeks later...

For those people..who may have stumbled on this due to similar issue...I ended up finding a solution to my problem...

 

What I have done is put the selection option in form tags with post method. And in my php code, I am doing this

 

 

If (isset($_POST('submit')) {

 

Carry on with whatever code you want.....

 

 

 

}

 

This way..it sets a force to the post function to post the values in the same page...you don't need action attribute for the form also..

 

Submit is the name and type of submit button I am using

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.