Ok so before I posted this I have been working on this code off and on for 2 weeks. Its probably so simple for someone. If any one could get me out of my rut I would so appreciate it!
Basically I'm trying to get a select box to display text from a database in a div tag from the select box populated by a while loop that also pulls from the database. The only way I can do this is from a javascript written by sending it over to a second page and I need it on just one page. Here is my code below:
<?php
session_start();
$q=$_GET["q"];
$num = $_GET['num'];
$test = $_GET['oneGram1'];
$_SESSION['oneGram']=$test;
$connect = mysql_connect("", "", "") or die("couldnt connect");
mysql_select_db("") or die("couldnt connect");
?>
<html>
<head>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<?php
$weight = mysql_query("SELECT * FROM WEIGHT WHERE NDB_No = $num");
echo"<form>";
echo"<select name='users' onchange='showUser(this.value)'>";
while($row5 = mysql_fetch_array($weight))
{
//$cal = $row5['Gm_Wgt'];
echo"<option value='$row5[Msre_Desc]'>$row5[Msre_Desc]</option>";
}
echo"</select>";
echo"<div id='txtHint'><b>Calorie info will be listed here.</b></div>";
echo"</form>";
$_SESSION['num1']=$num;
$sql1="SELECT * FROM WEIGHT WHERE NDB_No = '$num' AND Seq = 1";
$result1 = mysql_query($sql1);
while($row = mysql_fetch_array($result1))
{
$calories = $row['Gm_Wgt']*$test;
echo"<br>$test";
echo"<br>Calories = $calories";
echo "<br />";
}
?>
<br />
</body>
</html>
Even if this is a wrong way to go about doing this can someone post just a simple script using a select box and displaying data on the same page? thanks to anyone willing to help. :)