dongsanhu4784 2014-04-01 10:46
浏览 30

从mysql表填充的自动完成的输出

My textboxes get autocomplete populated from mysql tables.

I want to display the output list from the textbox into a selectable option instead of an list item.

echo '<li onClick="fill(\''.$result->naam_klant.'\');">'.$result->naam_klant.'</li>';

My code so far:

'<select onClick="fill(\''.$result->naam_klant.'\');"><option value=$result->naam_klant></option></select>';

Can you guys help me with this ?

UPDATE

    if(isset($_POST['queryString'])) {
         $queryString = $db->real_escape_string($_POST['queryString']);
        // Is the string length greater than 0?
        if(strlen($queryString) >0) {
            $query = $db->query("SELECT naam_klant FROM overboekingen WHERE naam_klant LIKE '$queryString%' LIMIT 10");     
            if($query) {
                 while ($result = $query ->fetch_object()) {
                     echo '<li onClick="fill(\''.$result->naam_klant.'\');">'.$result->naam_klant.'</li>';
                    '<select onClick="fill(\''.$result->naam_klant.'\');"><option value=$result->naam_klant></option></select>';
                }
            } else {
                echo 'ERROR: There was a problem with the query.';
            }
        } else {

        } // There is a queryString.
    } else {
        echo 'There should be no direct access to this naam_klant script!';
    }   
}

?>
  • 写回答

1条回答 默认 最新

  • dongmu2026 2014-04-01 11:17
    关注

    You don't give enough information, how you is your results structured?

    <select onchange="fill(this.value);" onfocus="this.selectedIndex = -1;">
    <? 
        for ($i=0; $i < count(results); $i++) { 
            $result = results[i];
            echo "<option value='{$result->naam_klant}'>option {$result->naam_klant}</option>
    ";
        }  
    ?>
    </select>
    

    Update

    Since you want a selectable option instead of an list item

    if ($query) {
       echo '<select onchange="fill(this.value);" onfocus="this.selectedIndex = -1;">
    ';
       while ($result = $query->fetch_object()) {
             echo '<option value={$result->naam_klant}>{$result->naam_klant}</option>
    ';
       }
       echo '</select>
    ';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办