I need to read Excel data and save into database, but ran in the problem below:
Excel format :
I need to save data in the database but the problem is that in message column some column start as [1/2-PNR], which means it has a long message that is divided into two parts as in [2/2-PNR]
But that message need to save in a single column
same as if message like [1/3-ADF] that is the message is divided into three parts and need to save in the database in single column
I tried saving the data with the code below, but unable to do so.
I used this zip file to read excel https://code.google.com/p/php-excel-reader/downloads/detail?name=php-excel-reader-2.21.zip
<?php
//error_reporting(0);
$host="localhost";
$username="root";
$password="";
$db_name="abro";
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select db");
ini_set("display_errors",1);
error_reporting(0);
require_once 'excel_reader2.php';
$date=date('d-M-Y',strtotime("-1 days"));
$actual_file=$date.".xls";
$xls = new Spreadsheet_Excel_Reader($actual_file);
$success=0;
for ($row=1;$row<=$xls->rowcount();$row++)
{
$mobile_no=$xls->val($row,1);
$party_name=$xls->val($row,2);
$message=$xls->val($row,3);
if($row==1)
{
}
else{
$query="insert into party_excel set
party_name='".mysql_real_escape_string($party_name)."',
message='".mysql_real_escape_string($message)."',
moble_no='".mysql_real_escape_string($mobile_no)."'
";
$query_run=mysql_query($query);
echo mysql_error();
$success++;
}
}
if($success>0)
{
echo "file imported successfully";
}
Actually this sheet is used to save SMS messages. If the SMS exceeds 160 characters then the remaining message is saved in next row. But when I show the message, I want to show the message on the same row.