Add new row in MYSQL from Comma Separated text in textbox(从文本框中的逗号分隔文本在 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
}
                        这篇关于从文本框中的逗号分隔文本在 MYSQL 中添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从文本框中的逗号分隔文本在 MYSQL 中添加新行
				
        
 
            
        - Mod使用GET变量将子域重写为PHP 2021-01-01
 - 从 PHP 中的输入表单获取日期 2022-01-01
 - PHP Count 布尔数组中真值的数量 2021-01-01
 - SoapClient 设置自定义 HTTP Header 2021-01-01
 - 如何定位 php.ini 文件 (xampp) 2022-01-01
 - Laravel 仓库 2022-01-01
 - 带有通配符的 Laravel 验证器 2021-01-01
 - 没有作曲家的 PSR4 自动加载 2022-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - 正确分离 PHP 中的逻辑/样式 2021-01-01
 
				
				
				
				