从文本框中的逗号分隔文本在 MYSQL 中添加新行
我有一个 PHP/MYsql 问题.
I have a PHP/MYsql question.
我试图在每个逗号后插入一个新行.
I am trying to insert a new row after each comma.
基本上,我想要这个功能:
Basically, I want this function:
假设我们有一个包含以下文本的文本框:
Let's say we have a textbox with the following text:
篮球、网球、足球、排球 --> 提交按钮
Basketball, Tennis, Futbol, Volleyball --> Submit Button
点击提交按钮后,我想在每个单词之后在一个表格中插入一个新行.
After the submit button is clicked, I want to Insert a new row in one table after each word.
基本上,我希望数据库中的结果是这样的
Basically, I want the outcome in the DB like this
id category
1 Basketball
2 Tennis
3 Futbol
4 Volleyball
谁能帮我解决这个问题?
Anyone can help me with this ?
谢谢:)
推荐答案
你可以循环遍历每一个,然后单独添加它们.
You could just loop through each, and add them individually.
$input = "Basketball, Tennis, Futbol, Volleyball";
foreach (explode(',',$input) as $piece)
{
$piece = mysql_real_escape_string(trim ($piece));
$sql = "INSERT INTO table VALUES($piece)";
//Run sql
}
相关文章