0

请帮助...用户在 textarea 中粘贴值导致添加新行...该新行正在处理并上传到 db 但某些列上没有值...我怎样才能消除多余的行在处理文本区域并上传到数据库之前?

这是我将文本区域处理为数组的代码:

$PhoneNumber = array_map('mysql_real_escape_string', explode("\r\n", $_POST['PhoneNumber']));
$Createdate = array_map('mysql_real_escape_string', explode("\r\n", $_POST['Createdate']));
$RemedyTicketNo = array_map('mysql_real_escape_string', explode("\r\n", $_POST['PhoneNumber']));

//确定元素数量最少的值

$min_count = min(count($PhoneNumber), count($Createdate), count($RemedyTicketNo));

//创建数组来保存INSERT值

$values = array();

//创建插入值

for($index=0; $index<$min_count; $index++)
{
$values[] = "('{$RemedyTicketNo[$index]}','{$PhoneNumber[$index]}','{$Createdate[$index]}',
'$Category2','$Category3','$Status','$Date','$Severity','$BanType','$XiD')";   
}

//插入数据库

if (isset($RemedyTicketNo)) 
{
$sql="INSERT into tbl_main
(ars_no,phone_number,create_date,category_1,category_2,status,resolved_date,trouble_type_priority,ban_type,employee_id_name)
VALUES " . implode (',',$values); 
$result=mysql_query($sql);

我试图合并此代码...但它似乎不起作用...

$lines = preg_split('/\n+/', trim($_POST['textarea']));
$text = implode("\n", $lines);

这是我使用上面的代码修改代码时的样子:

$PhoneNumber = preg_split('mysql_real_escape_string', '/\n+/', trim("\r\n", $_POST['PhoneNumber']));
$Createdate = preg_split('mysql_real_escape_string', '/\n+/', trim("\r\n", $_POST['Createdate']));
$RemedyTicketNo = preg_split('mysql_real_escape_string', '/\n+/', trim("\r\n", $_POST['PhoneNumber']));


if (isset($RemedyTicketNo)) 
{
$sql="INSERT into tbl_main
    (ars_no,phone_number,create_date,category_1,category_2,status,resolved_date,trouble_type_priority,ban_type,employee_id_name)
VALUES " . implode ('\n',$values); 
$result=mysql_query($sql);
4

1 回答 1

0

这已经修复了......我只是重新编辑了上面的代码,只添加了修剪,它起作用了:

$PhoneNumber = array_map('mysql_real_escape_string', explode("\r\n", trim($_POST['PhoneNumber'])));
$Createdate = array_map('mysql_real_escape_string', explode("\r\n", trim($_POST['Createdate'])));
$RemedyTicketNo = array_map('mysql_real_escape_string', explode("\r\n", trim($_POST['PhoneNumber'])));
于 2013-05-20T07:00:52.710 回答