我有一個用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