corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Need some php gods help please » Post Reply

Post Reply
Who Can Post? All users can post new topics and all users can reply.
Icon:
Formatting Mode:
Normal
Advanced
Help

Insert Bold text Insert Italicized text Insert Underlined text Insert Centered text Insert a Hyperlink Insert Email Hyperlink Insert an Image Insert Code Formatted text Insert Quoted text
Message:
HTML is Off
Smilies are On
BB Code is On
[img] Code is On
Post Options: Disable smileys?
Turn BBCode off?
Receive email notification of new replies?

pow

posted on 20th Apr 15 at 11:46

There is only maximum 300 lines in the csv, four bits of data (start time end time date and details), the csv is maximum 6kb, it loads just like any other light php page for me so I'm happy as it is. If it was loads of data I'd be doing it a little differently, however I cba to spend years on the school calendar lol


Dom

posted on 19th Apr 15 at 22:18

quote:
Originally posted by ed
fseek() works using bytes and not lines; you'd need to know how many bytes each line contained to use it.


Hence the 'incredibly messy approach' comment ;):lol:

Either way, it sounds like Pow is sorted which is the main thing :thumbs:


ed

posted on 19th Apr 15 at 21:05

fseek() works using bytes and not lines; you'd need to know how many bytes each line contained to use it. There's some OO stuff built which lets you seek to a line number, but it works still works recursively to find the line in the file you want.

That's why databases can be useful :)

[Edited on 19-04-2015 by ed]


Dom

posted on 19th Apr 15 at 20:50

quote:
Originally posted by ed
Yah, but PHP's IO is a bit sucky. You're stuck going through the file recursively no matter what as you can't set the file pointer manually, like you can do in other languages. Once you open the file up, the whole thing will be there in an array so you may as well slice it.


The fseek() function springs to mind (set pointer position, read X bytes; incredibly messy approach though) but I can't think of an elegant solution for CSV files in that you open the file and only grab X many rows from Y offset.

Personally i would have just dumped the CSV into a DB table and gone from there :lol: But i know that doesn't fit every scenario.

[Edited on 19-04-2015 by Dom]


ed

posted on 19th Apr 15 at 20:31

Yah, but PHP's IO is a bit sucky. You're stuck going through the file recursively no matter what as you can't set the file pointer manually, like you can do in other languages. Once you open the file up, the whole thing will be there in an array so you may as well slice it.


Dom

posted on 19th Apr 15 at 18:59

quote:
Originally posted by ed
Load the entire CSV into an array....


That makes me feel a little 'dirty'* :lol:

* I know, it depends on use, application etc etc


pow

posted on 18th Apr 15 at 10:41

I've done it :cool:

Thanks for you help everyone - Ed that array slice thing was the one :D


pow

posted on 17th Apr 15 at 16:26

Actually I'm managing to do it using a variable in the address as Steve suggested which is working nicely. You all may laugh but we gotta start somewhere!

[Edited on 17-04-2015 by pow]


pow

posted on 17th Apr 15 at 16:07

Dave help me :cry:


ed

posted on 17th Apr 15 at 15:53

This one's better :0

https://github.com/edcs/jquery-bootgrid


DaveyLC

posted on 17th Apr 15 at 15:51

e.g. http://www.jtable.org/Demo/PagingAndSorting


DaveyLC

posted on 17th Apr 15 at 15:49

You'd be better off getting PHP to serve up the Data as JSON then use a JQuery UI paged table plug-in to display it.


ed

posted on 17th Apr 15 at 15:44

Load the entire CSV into an array, then use array_slice() to get the parts of it you'd like.

i.e.

$paginated = array_slice($myCsvArray, 0, 20);

Will get you the first twenty rows of it and,

$paginated = array_slice($myCsvArray, 20, 20);

Will get you the next twenty. PHP's array handling is super quick; from first hand experience you'd need to be dealing with tens of thousands of rows before you notice a slowdown.


pow

posted on 17th Apr 15 at 15:13

It's not a DB backend though, it's a CSV - does that make a difference? I fucking hate websites!


Steve

posted on 17th Apr 15 at 14:10

so the link for the next button may look like

http://www.domain.com/cal.php?start=20&end=40

etc


Steve

posted on 17th Apr 15 at 14:08

Easy, put the DB query limit in a variable that is set by a HTTP post and get variable containing a number that relates to the start/end you are interested in, then just dynamically generate the link for the button to contain the correct numbers.


[Edited on 17-04-2015 by Steve]


pow

posted on 17th Apr 15 at 13:40

I am useless with php, I mostly steal code from helpful people on the internet :lol:

I have a list of data from a CSV document into a table: (Link Removed for now)

But I want to split that up so it shows 20 results per page with a next/previous button - how would I do this?

Thanks for any help in advance :wave:

[Edited on 17-04-2015 by pow]

[Edited on 18-04-2015 by pow]