質問

I have a code that pulls the name and id rows from a table, and populates a select box. It works great, but this select box is in an admin panel where an admin can delete entries from the database through this box. In the database, ID 0 is set to be the default text for another select box which is under the products section of the admin. So the entry id 0 needs to stay in the database regardless. Is there a way to populate this box with everything, except for ID 0 so it doesn't get accidentally deleted by an admin?

<?php
$result = mysql_query("SELECT id, name FROM drop_shippers");
echo '<label style="font-size: 12px;">Current Drop Shippers:</label>';
echo '<select name="selectedOption" style="width: 200px; font-size: 14px;" size=5 multiple>';
while($row=mysql_fetch_array($result))
{
    echo '<option value="' . htmlspecialchars($row['id']) . '">' 
        . htmlspecialchars($row['name']) 
        . '</option>';
}
echo '</select>';
?>

Any help is appreciated!

役に立ちましたか?

解決

A much (much) better way would simply be to add default information separately from the database - don't store a "default" item from the database, put it in your code.

To answer your question, however, use this:

$result = mysql_query("SELECT id, name FROM drop_shippers WHERE id > 0");
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top