我有一个用HTML编写的网页。我有一个是通过利用MySQL查询数据库中填充的下拉列表:在PHP/HTML网页中执行多个MySQL查询:只有第一个查询运行
<SELECT NAME = "Participant" STYLE = "WIDTH: 187" TITLE="Begin typing participant last name for fast searching." required>
<OPTION SELECTED VALUE = "">Select Participant...</OPTION>
<?PHP
$allParticipants = getall_participants();
foreach($allParticipants as &$value) {
$dt = date('Y-m-d');
$val = $value->get_id();
$optval = $dt.$val;
echo "<OPTION VALUE='",$optval,"'>";
echo $value->get_first_name()," ",$value->get_last_name();
echo "</OPTION>";
}
?>
</SELECT>
的getall_participants()看起来像:
function getall_participants() {
connect();
$query = "SELECT * FROM dbParticipants ORDER BY last_name";
$result = mysql_query ($query);
$theParticipant = array();
while ($result_row = mysql_fetch_assoc($result)) {
$theParticipant = new Participant($result_row['last_name'],
$result_row['first_name'], $result_row['address']);
$theParticipants[] = $theParticipant;
}
mysql_close();
return $theParticipants;
}
这同一页上我有一个文本框是预填写的另一个数据库:
<?php
$dt = date('Y-m-d');
$participants = getall_dbParticipantEntry_byDate($dt);
foreach($participants as &$value) {
$a = $a.$value.", ";
}
echo "<INPUT TYPE='text' NAME='Participants' STYLE='WIDTH:50px;' TITLE='Participants' ";
echo "VALUE='[", $a.' ', "]'/>";
?>
这getall_dbParticipantEntry_byDate($日期)看起来像:
function getall_dbParticipantEntry_byDate($date) {
connect();
$query = 'SELECT * FROM dbParticipantEntry WHERE date = "'.$date.'"';
$result = mysql_query ($query);
$theParticipantEntry = array();
while ($result_row = mysql_fetch_assoc($result)) {
$theParticipantEntry = new ParticipantEntry($result_row['date'], $result_row['id'], $result_row['call_time'],
$result_row['result'], $result_row['notes']);
$theParticipantEntries[] = $theParticipantEntry->get_id();
}
mysql_close();
return $theParticipantEntries;
}
但是,虽然这两个函数都能单独工作,但当它们都在同一个网页上时(就像我的意思是),只有第一个函数运行。我通过切换它们进行测试。他们都完成了他们的指定任务,但只能在页面上单独完成。 我怎样才能让他们都运行并填充他们各自的领域?
非常感谢。
我关闭了连接,但后来我在下一个函数中重新连接。这还不够吗? – 2012-04-06 23:41:19
你如何连接? – Kerwindena 2012-04-06 23:48:21
通过“connect();”在PHP中。不重新连接到数据库? – 2012-04-06 23:49:32