dopii22884 2014-11-20 03:46
浏览 38
已采纳

空的选择字段表单值会留下不需要的空白区域

I will get right to it, I am having a small difficulty with my php code provided below. I have 10 form fields connected to my mysql database, the code below basically grabs existing data that has been submitted in the form fields named "item1, item2, item3, etc... and displays it in the select form field once clicked. This code repeats for an additional 9 form fields. See below:

<?php
        $sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY status ORDER BY status";
        $sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query"     '.$sql);
        while ($row = mysql_fetch_assoc($sql_result)) {
            echo "<option value='".$row["item1"]."'".($row["item1"]==$_REQUEST["item1"] ? " selected" : "").">".$row["item1"]."</option>";
        }
    ?>


if ($_REQUEST["item1"]<>'') {
    $search_item1 = " AND item1='".mysql_real_escape_string($_REQUEST["item1"])."'";    
}

When I fill out, let's say 3 of 10 form fields, leaving 7 empty, the empty values are displayed in the select form field once i click on the select field. I have provided a picture to show what I'm talking about. See below:

Select Form Field

I need the empty values to stop adding an empty space in these fields, if someone could help me with this it would be much appreciated.

Thx.

  • 写回答

1条回答 默认 最新

  • duanchun2349 2014-11-20 03:56
    关注

    I think you can limit that by adding WHERE item1 != ''

    Or if the field contains white space than you can use:

    if (!empty(trim($row["item1"]))) { echo "<option value='".$row["item1"]."'".($row["item1"]==$_REQUEST["item1"] ? " selected" : "").">".$row["item1"]."</option>"; }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类