这里是初学者;我已经搜索了很多例子,仍然需要一些帮助。我希望用户从下拉框中选择一个选项,该选项将查询 mysql 中的表。我不明白如何(在我的 html 文件中)在 getprojectstatus.php 中显示 select 语句。
<html>
<head>
<title>Status Dashboard</title>
</head>
<body style="background:#19245e url('images/fade.png')repeat-x;font-size:12px;font-family: Arial;line-height:18px;color:#FFFFFF;">
<script>
function displayProject(option)
{
var x;
if (option=='sciplay')
{
x="show Sciplay selected, show notes, status, etc..."
}
else if (option=='oklahoma')
{
x="show OK selected, show..."
}
else if (option=='northdakota')
{
x="show North Dakota selected, show..."
}
else if (option=='audit')
{
x="show Audit selected, show..."
}
else if (option=='sggaming')
{
x="show SG Gaming selected, show..."
}
else if (option=='all')
{
x="..."//(option=(1+2+3+4+5))
}
document.getElementById("demo").innerHTML=x;
}
</script>
<div align="center">
<TABLE BORDER="1">
<TR>
<TD><img src='images/header.png'/>
</TD>
</TR>
<TR>
<TD>
<TABLE BORDER="0" bgcolor="C0C0C0" align="left">
<TH>Projects
</TH>
<TR>
<TD>
<FORM action="getprojectstatus.php" method="post">
<SELECT onload="displayProject(this.value);" onchange="displayProject(this.value);">
<OPTION VALUE='all'>ALL</OPTION>
<OPTION VALUE='sciplay'>Sciplay</OPTION>
<OPTION VALUE='oklahoma'>Oklahoma</OPTION>
<OPTION VALUE='northdakota'>North Dakota</OPTION>
<OPTION VALUE='audit'>Audit SSAE16</OPTION>
<OPTION VALUE='sggaming'>SG Gaming</OPTION>
</SELECT>
</FORM>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD>
<p id="demo">
</p>
</TD>
</TR>
</TABLE>
</div>
</body>
和我的 getprojectstatus.php 文件:
<?php
//create connection variables
$host=`localhost`;
$user=`dashboard`;
$pw=`password`;
$db=`status`;
//create connection
$con=mysqli_connect("$host", "$user", "$pw", "$db");
//check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//take input from form and store as var queries
$option= $_POST['option'];
if ($option == 'sciplay')
{
$queries = "SELECT * FROM status where project=1"
}
else if ($option == 'oklahoma')
{
$queries = "SELECT * FROM status where project=2"
}
else if ($option == 'northdakota')
{
$queries = "SELECT * FROM status where project=3"
}
else if ($option == 'audit')
{
$queries = "SELECT * FROM status where project=4"
}
else if ($option == 'sggaming')
{
$queries = "SELECT * FROM status where project=5"
}
else ($option == 'all')
{
$queries = "SELECT * FROM status"
}
//store query as var result
$queries=$query;
$result=@mysqli_query($con,"$query");
//echo var result in table format
echo "<table border='1'>
<tr>
<th>Project</th>
<th>Subject</th>
<th>Status</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['project'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . $row['entry'] . "</td>";
echo "</tr>";
}
echo "</table>";
//close mysql connection
mysqli_close($con);
?>
提前感谢您的帮助!