supercone Posted October 24, 2013 Share Posted October 24, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283247-pass-select-value-to-same-php-page/ Share on other sites More sharing options...
iarp Posted October 24, 2013 Share Posted October 24, 2013 <form id="myform" method="GET" action="<?php echo $_SERVER['$PHP_SELF'];?>"> You don't need to $ on $PHP_SELF, just PHP_SELF. But then again, if you just want the submission to go to the same page, you don't even need an action="" element. Quote Link to comment https://forums.phpfreaks.com/topic/283247-pass-select-value-to-same-php-page/#findComment-1455289 Share on other sites More sharing options...
supercone Posted October 24, 2013 Author Share Posted October 24, 2013 I will try that..but I remember that I started out without putting any action or PHP_SELF...and that didn't work..but I'll still give it a try...thank you.. Quote Link to comment https://forums.phpfreaks.com/topic/283247-pass-select-value-to-same-php-page/#findComment-1455312 Share on other sites More sharing options...
supercone Posted November 18, 2013 Author Share Posted November 18, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/283247-pass-select-value-to-same-php-page/#findComment-1458864 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.