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 中添加新行
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
