dcole07 Posted March 1, 2006 Share Posted March 1, 2006 I've tried to split data into group of 10 from a txt file but I need helpIn the txt file each group is one line and I want 10 line to be put into something like ?page#1 page#2...then it will display 1-10 if the url has ?page#1, 11-20 if the page is #2 ...What would the script be? Quote Link to comment Share on other sites More sharing options...
ken311 Posted April 30, 2008 Share Posted April 30, 2008 Can you give us an example of the text in the text file or the code you are trying? this is very vague.You might want to try using:$array = explode("/r/n",$filecontents);That will split your contents into an array and then you can use a for loop to manage the values. Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 30, 2008 Share Posted April 30, 2008 I imagine the text file is:data1.1, data1.2, data1.3...data2.1, data2.2, data2.3.......data11.1, data11.2, data11.3...data12.1, data12.2, data12.3...Why not use a database then? It would be way more efficient. Anyway, as suggested above, use explode to have the groups in an array. Seperate each ten group with a word (like: "--next group--") or two brakes to explode them easily. Then depending on the page, show the info. Smth like this:[code]<?php$handle = fopen('file.txt', 'r'); //open file as read only$contents = fread($handle, filesize('file.txt')); //read the file$data = explode('--next group--', $file); //explode the groupsif(isset($_GET['page']) and $_GET['page'] != count($data) + 1){ //the whole block: sets the key of the array depending on the page $dataKey = $_GET['page'] - 1; } else{ $dataKey = 0;}echo $data[$dataKey];?>[/code]The idea of all that, is to get the page data and use it as the key of the array. So for page=1, u could show array[0] (as array keys start from 0) and so on. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.