dongzuozhu66776 2013-08-29 00:23
浏览 31
已采纳

从填充选择框中排除int = 0

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!

  • 写回答

1条回答 默认 最新

  • douchuanghan1344 2013-08-29 00:28
    关注

    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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?