如何让PHP读取下拉框中的字符串? [英] how to get php to read in a string of words from a dropdown box?

查看:105
本文介绍了如何让PHP读取下拉框中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常感谢你们的帮助。这似乎是一件容易的事情,我觉得我只是碰壁,不知道如何解决它。



我会试着解释我在做什么并且希望它有意义。



我使用数据库填充我的下拉框,下拉框类似于:

  echo< form action ='process_form.php'method ='post'>; 
回显选择一个项目< br />;
echo< select name ='item'id ='item'>;
//数据库已连接并且选择查询已成功执行。 $ result是选择查询结果。
while($ row = mysql_fetch_array($ result))
{
//每行包含多个单词,如裁缝模特大小12
echo<选项值=。 $ row ['style']。 > 中。 $行[风格。 < /选项> 中。 < br />;
}
...
...

下拉框被填充正确的数据。



然后用户从下拉框中选择一个项目,然后点击提交按钮。



我需要知道用户选择了哪个项目来计算其运费,但是当我使用 $ _ POST ['item'] 来试图找出哪个项目被选中时,我得到第一个字裁缝,其余的失踪!



请帮助我获得整个字符串。



很多人提前致谢。

抱歉,我对论坛完全陌生,甚至不知道如何发布或跟进问题。如果你们也可以帮我解决这个问题。目前,我正在努力发表我的后续问题......希望这会显示出来......

希望地,你的MYSQL数据库有一个主键?如果是这样,请将每个< option> 设置为该项目的主键。



例如:

SQL

  id desc 
1裁缝与人体模型的东西
2裁缝的东西没有人体模型

表单PHP

  echo< option value ='。$ query ['id' ] '> 中$查询[ '降序']。 < /选项> 中; 

提交表单时,请重新查询数据库以获取所需的描述。你会这样做重新查询以检索价格,是吗?



发生这种情况的原因是HTML属性中不鼓励使用空格。你不应该有像 value ='这个属性间隔的属性


thank you all so very much for helping. It's seemingly such an easy task, and I feel I just hit a brick wall and not knowing how to fix it.

I'll try to explain what I am doing a bit more and hope it makes sense.

I used a database to populate my dropdown box, dropdown box is something like:

echo "<form action='process_form.php' method='post'>";
echo "Select an item<br />";
echo "<select name='item' id='item'>";
//database was connected and select query was executed succesfully. $result was the select query result.
while($row = mysql_fetch_array($result))
{
//each row contains more than one words, something like "dressmaker mannequin size 12"
echo "<option value=" . $row['style'] . ">" . $row['style']. "</option>" . "<br />";
}
...
...

Dropdown box was populated with correct data.

Then user selects an item from this drop down box, and clicks the submit button.

I need to know which item user has selected in order to calculate its shipping costs, but when I use $_POST['item'] to try to find out which item was selected, I get the first word "dressmaker", the rests were missing!

Please help me to obtain the whole string of words.

Many many thanks in advance.

Sorry I am completely new to forums, and I don't even know how to post or follow up with a question. If you guys can help me on this as well. At the moment, I am struggling to post my follow up questions ... hope this will show up ...

解决方案

Hopefully, your MYSQL database has a primary key? If it does, set the value of each <option> to the primary key of the item.

For example:

SQL

id  desc
1   "dressmaker thing with mannequin"
2   "dressmaker thing no mannequin"

Form PHP

echo "<option value='".$query['id']."'>".$query['desc']."</option>";

When form is submitted, re-query the database for the desired description. You'll be doing this re-query anyway to retrieve prices and such, yes?

The reason this is happening is that spaces are discouraged in HTML attributes. You shouldn't have an attribute like value='this attribute is spaced'.

这篇关于如何让PHP读取下拉框中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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