开发者

Can I pull data from a .xls file with PHP, sort and call the data without MySQL?

I'm learning basic PHP at this point. I have a .xls (Excel, converted from Numbers on the mac) file that I want to call upon for data.

Currently the table has 3 columns: Team Name, Conference and Division and for each column there are 32 total rows (not including the row for labels)

My goal with this simple program is to read in this table, and build a simple UI so that when I clic开发者_如何学Gok on a Division, it shows the four teams in that division.

Can this be done without MySql? Should I be reading the .xls file into the .html file where the user will interact with the buttons or into the .php file that the .html file links to.


If you open the file in Excel, go to File, and click on Save As, you'll get a normal save dialog. Here, select .csv, rather than .xls. This is a format both PHP and Excel understand.

Call fgetcsv to read the data from the file into an array, and fputcsv to write one of these arrays (modified if required) to a CSV file.


There PHPExcel which can read/write .xls files (actual native .xls, not .csv renamed to .xls).


For reading xls files, you can try smt like this. However, in my opinion, it would be much easier if you save your xls as csv, and then read it.

For the no-mysql part, you can create your own data structure and use it like that. You could use multidimensional arrays for that purpose.

If speed is the key, you should sort the data based on a certain column for quicker searching (you could then use binary search). Or, even better, you could use hash tables.

Here is a description on csv reading: http://php.net/manual/en/function.fgetcsv.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜