テーブルを更新するためにselectオプションを使いたいと思います。 これはコードですが、試してみるとデータは表示されていません。ヘルプをしてください....phpとmysqlのselectオプションを使用してテーブルを更新する方法
これらのコードは選択オプションです。
<form method="POST">
<text class="sort"><span>Course:</span></text>
<select class="sel" name="select_course" id="select_course">
<?php
$query=mysqli_query($conn,"select DISTINCT Course from `tbl_student`");
\t \t while($row=mysqli_fetch_array($query)){
\t \t \t ?>
<option><?php echo $row['Course'];?></option>
<?php
}
?>
</select>
<input class="btnsearch" type="button" name="submit" value="Search">
<input class="btn" type="button" name="btn_add" value="Add Student">
<input class="btn_import" type="button" name="import" value="Import File">
そして、これらのコードは、テーブルにデータを表示するためのものです。
<?php
echo '<table>
<tr>
<td>name</td>
<td>Id number</td>
<td>Course</td>
<td>School Year</td>
<td>Semester</td>
</tr>';
if(isset($_POST['submit']))
{
$result2 = mysqli_query($conn, "Select name,id_number,Course,school_year,semester from tbl_student where Course='".$_POST['select_course']."'");
while($row=mysqli_fetch_row($result2)){
echo '<tr>
<td>'.$row["name"].'</td>
<td>'.$row["id_number"].'</td>
<td>'.$row["Course"].'</td>
<td>'.$row["school_year"].'</td>
<td>'.$row["semester"].'</td>
</tr>';
}
echo '</table>';
}
?>
</form>
私はテーブルが自動的に更新されます選択オプションから選択したときに私が欲しいのです。
ajaxとonchangeイベントがなければ、選択した変更に基づいて実行することはできません。そのためのフォームをPHPに送信する必要があります – clearshot66
あなたのコードは[** SQLインジェクション**](https://en.wikipedia.org/wiki/SQL_injection)攻撃に対して脆弱です。あなたは[** mysqli **](https://secure.php.net/manual/en/mysqli.prepare.php)または[** PDO **](https ://secure.php.net/manual/en/pdo.prepared-statements.php)ドライバ。 [**この記事**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)には、いくつかの良い例があります。 –