At 4:28 PM -0500 1/10/02, Erik Price wrote:
>
>PS: what I am -really- trying to do is dynamically fill in a
><select> listbox with <options> that correspond to all of the
>records in a given table. Like so:
>
><form>
> <select>
> <?php
> foreach ($record_id_and_record_name_pair_pulled_from_mysql_query) {
> print("<option value=\"${record_id}\">${record_name}</option>");
> }
> ?>
> </select>
></form>
>
>but I am unsure of how to grab multiple values from the
>mysql_query() and load them into an array. Has anyone done this
>before?
>
I've just recently done something very similar. The code is below. It
looks a bit different because I like to include very little HTML in
my PHP. But otherwise the concept should be the same.
I should mention, that my code actually produces two pull down menu.
My ultimate goal was to add a javascript to the sequence, so that
when a user selects the item in the first pull down, it resubmits the
query for the second pull down, and allows for pull down two to be
dependent on pull down one. I haven't worked on the javascript as of
yet.
......................
$staffID=$id;
$results=mysql_query ("
SELECT staff.staffID, teamMembers.accountID,
accounts.clientID, clients.orgID,
orgs.name AS client, accounts.description AS account
FROM staff, clients, orgs, accounts LEFT JOIN teamMembers ON
teamMembers.accountID=accounts.accountID
WHERE teamMembers.staffID=\"$staffID\" AND
teamMembers.accountID=accounts.accountID
GROUP BY accounts.description
ORDER BY orgs.name") or die("I've failed! Woe is ME!");
while ($row=mysql_fetch_array($results)){
$staffID = $row["staffID"];
$accountID = $row["accountID"];
$clientID = $row["clientID"];
$orgID = $row["orgID"];
$client = $row["client"];
$account = $row["account"];
// After the array is created, a small if elseif script is used
to create the select menu.
// Ideally the to menus will be separate scripts, I just want to
test the theory first
if($clientID != ""){
$selectClient .=
"<option value=\"$clientID\" selected=\"$client\">$client</option>\n";
} else {
$selectClient .=
"<select id=\"clientID\" name=\"client\">
<option value=\"\" selected=\" \"> </option>\n";
}
// Pull down list2, this displays the accounts pull down.
if($accountID != ""){
$selectAccount .=
"<option value=\"$accountID\"
selected=\"$account\">$account</option>\n";
} else {
$selectClient .=
"<select id=\"accountID\" name=\"account\">
<option value=\"\" selected=\" \"> </option>\n";
}
}
?>
<!-- This Script is a Modification of Code Created By Joe Chellman to
auto create pull down menus from enum (value lists). I've adjusted it
to just pull field data -->
<p><select id="clientID" name="client">
<option value=" " selected=" "> </option>
<? echo"$selectClient\n"; ?>
</select></p>
<p></p>
<p><select id="accountID" name="account">
<option value=" " selected=" "> </option>
<? echo"$selectAccount\n"; ?>
</select></p>
...................................
--
.........................................
Alnisa Allgood
Executive Director
Nonprofit Tech
(ph) 415.337.7412 (fx) 415.337.7927
(url) http://www.nonprofit-techworld.org
(url) http://www.nonprofit-tech.org
(url) http://www.tech-library.org
.........................................
Nonprofit Tech E-Update
mailto:[EMAIL PROTECTED]
.........................................
transforming nonprofits through technology
.........................................
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]