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 中添加新行
				
        
 
            
        基础教程推荐
- php中的PDF导出 2022-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				