爆炸并将值插入多个列

时间:2013-09-08 13:17:02

标签: php mysql explode

我需要先按行分解字符串,然后按#并插入mysql。

就像我有一个字符串

Shahbaz#is my name
Singh#is my caste

我希望脚本首先按新行展开字符串,将Shahbaz插入word列,将is my name插入mysql中的note列,并与之相同Singhis my caste

include("connect.php");
$counter = 0;
$counters = 0;
$string = mysql_real_escape_string($_POST['words']);
$arr = explode(" ", $string);
mysql_query("SET charset utf8");
$sql = mysql_query("SELECT `word` FROM unicode WHERE word IN ('".implode("', '", $arr) . "')") or die (mysql_error());
$dupes = array();
while($r = mysql_fetch_assoc($sql)) {
    $dupes[] = $r['word'];
}
$newwords = array_diff($arr, $dupes);
if(count($newwords)) {
     $sqli = mysql_query("INSERT INTO unicode (word) VALUES ('" . implode("'),('", $newwords) . "')") or die (mysql_error());
}

在此脚本中,它会插入每个单词,但不会插入注释列。它用空格分隔单词。我希望它用新行分隔,然后将#后的文本插入note列...

提前致谢。

0 个答案:

没有答案
相关问题