使用 SQL 数据库字段将名称添加到输入字段 [英] Adding name to input field using SQL database field

查看:37
本文介绍了使用 SQL 数据库字段将名称添加到输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想要做的是将 name='' value 添加到下拉列表中的 option.这一切都非常简单,只需使用 HTML.但我希望 name value 来自我正在排队的数据库.但是数据库字符串在单词之间有空格,这就导致了一个问题.我需要字符串是 Eten &Drinken 而不是它现在的输出方式,请参见下面的示例.

So what I'm trying to do is add a name='' value to an option in a drop down list. This all is pretty simple using just HTML. But I would like to have the name value be from the database I'm queuing. But the database string has spaces in between the words, and this causes a problem. I need the string to be Eten & drinken and not the way it outputs now, see example below.

现在,我有这个:

   <?php $q = $row["Categorie"];
        echo    "   
            <option value=".$q." name=".$q.">
               ".$row["Categorie"]."&nbsp;&nbsp;
                   <span style='font-size:1.2rem;color:#F8F8F8;'>(" . $row['x'] .  ")
                   </span>
            </option>
    ";?>

如果我查看源代码,它会输出以下内容:

Which outputs the following if I look at the source:

<option value="eten-en-drinken" name="Eten" &amp;="" drinken="">
    Eten &amp; drinken&nbsp;&nbsp;(19)
</option>

我尝试搜索 google 和 str_replacehtmlspecialcharsutf8_encode 并将 name 更改为 数据类型 但注意工作.我只是希望它是 Eten en Drinken.我需要在第二个下拉菜单中使用这个确切的值.有什么想法、文档或帮助吗?

I've tried searching google and str_replace, htmlspecialchars, utf8_encode and changed name to data-type but noting works. I just want it to be Eten en drinken. I need this exact value for use in a second drop down menu. Any thoughts, documentation or help?

推荐答案

您的问题可以通过为 name 属性添加缺少的引号来解决.

Your problem migh be solved by adding missing quotes for name attribute.

echo    "   
        <option value=".$q." name='".$q."'>..."

这篇关于使用 SQL 数据库字段将名称添加到输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆