1

ここは初心者です。多くの例を検索しましたが、まだ助けが必要です。ユーザーがドロップダウン ボックスからオプションを選択すると、そのオプションが 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);
?>

事前に助けてくれてありがとう!

4

2 に答える 2