我有这段PHP代码 - 目的是连接到MySQL数据库,返回'title'的所有值,然后返回该标题的'date_time'的所有值。但是,我无法设置会话变量,而date_time可以调用该会话变量来查找相关数据。
这是我的代码:
<p>
<form action="ShowSelect.php" method="post">
<SELECT NAME="title" onchange = "$_SESSION['title']=title">
<option value="--"> Please Select a show</option>
<?php
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql= "SELECT title FROM production";
$handle = $conn->prepare($sql);
$handle->execute();
$res = $handle->fetchAll();
foreach($res as $row) {
echo '<option>'. $row['title'] .'</option>';
}
?>
</SELECT>
</form>
<form action="ShowSelect.php" method="post">
<select NAME="date_time">
<option value="--"> Please Select a time</option>
<?php
$conn = new PDO("mysql:host=$host;dbname=$dbname", $user, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT date_time FROM performance WHERE title='{$_SESSION['title']}'";
$handle = $conn->prepare($sql);
$handle->execute();
$res = $handle->fetchAll();
foreach($res as $row) {
echo '<option>'. $row['date_time'] .'</option>';
}
$_SESSION['date'] = 'date_time';
?>
</select>
</form>
</p>
我遇到的问题是“动态”更新第二个数据库调用。有人能指出我正确的方向吗?
谢谢!