Hi all,
I have written a php coding for uploading a csv file to database. I want to know the last row of the csv file. How to calculate the the last row of the excel file using php coding. Please anyone give me help.... I am not good in english if u found any mistake in my words plz dont mistake me......
Please send me the php coding to calculate the last row of excel file....
thanks.
8 19243 Atli 5,058
Recognized Expert Expert
Hi.
Have you made any attempt at this yourself?
Could we see what you did?
Why (how) did it not work?
Are you getting any errors?
We are more than happy to help you solve problems you are having with your code, but we won't write the code for you.
Hi.
Have you made any attempt at this yourself?
Could we see what you did?
Why (how) did it not work?
Are you getting any errors?
We are more than happy to help you solve problems you are having with your code, but we won't write the code for you.
-
<?php
-
session_start();
-
?>
-
<?php
-
$name1=$_SESSION['name'];
-
$file1=$_SESSION['path'];
-
echo $file1;
-
echo "<br/>";
-
require_once('reader.php'); // include the class
-
$data = new Spreadsheet_Excel_Reader(); // instantiate the object
-
$data->setOutputEncoding('CP1251'); // select output encoding
-
$data->read("$file1/*.xls"); // specify the file to read
-
/* We start reading the file from row 4 because that's where the
-
data in the table starts */
-
$startRow = 2;
-
-
/* Get all the cells of the sheet */
-
$cells = $data->sheets[0]['cells'];
-
/* We create a nice table to display the data */
-
// echo "<table border='1' style='font-size:14px;font-family:Arial;'>
-
// <tr><td>Phone No.</td><td>First Name</td><td>Last Name</td><td>Address1</td><td>Address2</td><td>State</td><td>City</td>
-
// <td>Zip</td></tr>";
-
/* Loop through the table. In this case we know that the table has only
-
4 rows.*/
-
for ($row = $startRow;$row <= 10;$row++)
-
-
{
-
/* Assign all the columns */
-
$phone = $cells[$row][1];
-
$firstname = $cells[$row][2];
-
$lastname = $cells[$row][3];
-
$address1 = $cells[$row][4];
-
$address2 = $cells[$row][5];
-
$state = $cells[$row][6];
-
$city = $cells[$row][7];
-
$zip = $cells[$row][8];
-
$id = $cells[$row][9];
-
/* Then display them
-
echo "<tr><td>" . $phone . "</td>";
-
echo "<td>" . $firstname . "</td>";
-
echo "<td>" . $lastname . "</td>";
-
echo "<td>" . $address1 . "</td>";
-
echo "<td>" . $address2 . "</td>";
-
echo "<td>" . $state . "</td>";
-
echo "<td>" . $city . "</td>";
-
echo "<td>" . $zip . "</td>";
-
echo "<td>" . $id . "</td></tr>"; */
-
mysql_connect('localhost','root','123456');
-
mysql_select_db("dialer");
-
mysql_query("insert into $name1(phone,firstname,lastname,address1,address2,state,city,zip)values('$phone','$firstname',
-
'$lastname','$address1','$address2','$state','$city','$zip')");
-
}
-
echo "Successfully Inserted";
-
?>
-
In this code I used one for loop that loop I specified the range limit that is 10 ,
we don't know how many rows data is there .so that I want the last
row in every file how to find .
Atli 5,058
Recognized Expert Expert
OK. I think I understand how the Spreadsheet_Excel_Reader object works.
You should be able to find the last row somewhat like this: -
# Get first sheet
-
$sheet = $data->sheets[0];
-
-
# Get all rows in the sheet
-
$rows = $sheet['cells'];;
-
-
# Find total number of rows
-
$rowCount = count($rows);
-
-
# Show data from last row
-
echo "<table><tr>";
-
foreach($rows[$rowCount -1] as $col) {
-
echo "<td>$col</td>";
-
}
-
echo "</tr></table>";
-
P.S.
Please use [code] tags when posting source code. It is impossible to read your code without them!
hi Atli,
I thank a lot.........
Its now working perfectly.......
Again thank a lot...........
May I ask where you got that reader.php script? I would like very much to be able to read xls documents.
Thanks.
Atli 5,058
Recognized Expert Expert
Hi.
I Googled the class name and I found this link.
I think this is what he is using, tho there may be a small bug in the reader.php code. Namely the require_once function at line 31 may need to be altered to fit the downloaded files.
@Atli
where to download the 'OLERead.php' file that required in line 31..?
I didnt read your code.
But from you initial question I am totally confused.
I want to know the last row of the csv file. How to calculate the the last row of the excel file using php coding.
What do you want last row of csv file or last row or excel file or both?
do you actually need last row of the file or count of rows?
in case of php you dont need any special software. But in case of excel I would suggest you to try PHPExcel. If you download PHPExcel you will also get OLERead.php file.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: deko |
last post by:
Below are the contents file that has the IP address and time of visit of
visitors to a website.
68.122.69.241|1089822686
68.122.69.241|1089823630
68.122.69.241|1089823638
|
by: Ling Lee |
last post by:
Hi all.
I'm trying to write a program that:
1) Ask me what file I want to count number of lines in, and then counts the
lines and writes the answear out.
2) I made the first part like this:
...
|
by: Hari Om |
last post by:
Here are the details of my error log files:
I execute the command and get following message at console:
----------------------------------------------------------------------
../sqlldr...
|
by: keith |
last post by:
I am trying to get a exact count of different distinct entries in an
Access column. At first, I was trying to work with three columns, but
I've narrowed it down to one to simplify it. I've searched...
|
by: Martin Joergensen |
last post by:
Hi,
I have some files which has the following content:
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 0 0 0 0
|
by: TechnoPup |
last post by:
Greetings,
I am very new to working with databases, and I am not sure how to go about structuring the query I need. What I have is an Access database with approx. 400,000 records in 5 fields. ...
|
by: danibecr |
last post by:
I'm trying to make a table that will daily count the records imported and save them to a seperate table along with the date imported. But as of now after all the processing is complete I delete...
|
by: marianowic |
last post by:
Hello.
I'm trying to get a real number of used (where is any data) rows in a
Excel file in a C# code.
I found some examples abount Excel.Range but it still isn't good.
Does anyone have any ide...
|
by: lovecreatesbea... |
last post by:
It takes mu so time to finish this C source code line count function.
What do you think about it?
/
*******************************************************************************
* Function ...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |