| | |
|
|
|
Dynamic PHP Drop Down List... |
| message from svnipp on 15 Jul 2004 |
I have created a drop-down list on a page that is populated from a MySQL
database via PHP. The problem I am running into is that the display of this
list defaults to showing the last item on the list by default. Basically, the
display defaults to showing the bottom of the list rather than the top. I have
not been able to figure out how to tell DreamWeaver that I want the behavior of
this drop-down to be opposite. I want the list to default to displaying the
top. I can code the by hand in PHP, but I have been trying to use DreamWeaver
for this except where absolutely necessary. My coding of this by hand will
completely change the manner in which the drop-down list is created. Here is
the DreamWeaver generated PHP...
<select name="host" size="1">
<option value="value" <?php if (!(strcmp("value",
$row_Hosts['host']))) {echo "SELECTED";} ?>>System Name</option>
<option value="spacer" <?php if (!(strcmp("spacer",
$row_Hosts['host']))) {echo "SELECTED";} ?>>----------------</option>
<?php
do {
?>
<option value="<?php echo $row_Hosts['host']?>"<?php if
(!(strcmp($row_Hosts['host'], $row_Hosts['host']))) {echo "SELECTED";} ?>><?php
echo $row_Hosts['host']?></option>
<?php
} while ($row_Hosts = mysql_fetch_assoc($Hosts));
$rows = mysql_num_rows($Hosts);
if($rows > 0) {
mysql_data_seek($Hosts, 0);
$row_Hosts = mysql_fetch_assoc($Hosts);
}
?>
</select>
Thanks in advance for any help.
Scott
|
| Joe Makowiec replied to svnipp on 15 Jul 2004 |
I gather that what you want is to have "System Name" displaying in the
dropdown box? If so, then do this - eliminate all the <?php if (!(strcmp(...?>
blocks, and make the first option selected:
<select name="host" size="1">
<option value="value" selected="selected">System Name</option>
<option value="spacer">----------------</option>
<?php do {
?>
<option value="<?php echo $row_Hosts['host']?>"><?php echo $row_Hosts['host']?></option>
Without seeing your data, I'd guess that the test is matching every data
item, and it's marking every option as selected.
|
| -Rb replied to svnipp on 15 Jul 2004 |
?>><?php
If I am understanding your question correctly, it
appears that you would need to "ORDER BY" in your
SQL statement to sort the list.
HTH
-Rb
|
|
Archived message: Dynamic PHP Drop Down List... (Macromedia Dreamweaver Web Design)