PHP Outputting finite amount of lines from a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PHP Outputting finite amount of lines from a file
# 1  
Old 10-11-2005
PHP Output specified amount of lines from a file

Hi, I have the code below which outputs all the lines of a CSV file but I'd like it to only output 15 lines then save the current line as a variable which could be used (as a link) to display the next 15 lines. I can't get my head around the logic! Please help Smilie

while ($data = fgetcsv($fp, 1000, "~")){
$num = count ($data);
$i++;
print '<td>';
print "<a href=\"" . $data[2] ."\"><img src=\"" . $data[2] . "\"></a><br>";
print "Submitted by:<br>";
print $data[1];
print '</td>';

if ($i == 5){
print '</tr>';
$i=0;
}
}
print '</table>';
fclose ($fp);

Many thanks,
Smilie

Last edited by pondlife; 10-11-2005 at 12:44 PM..
# 2  
Old 10-26-2005
Solution found!

I went with a database solution in the end but the method to display the output would've been the same - here's the final code:

print '<table class="tborder" border="0" width="95%" align="center">';
$t=0;
print '<tr>';
while ($data=mysql_fetch_array($result)) {
// include code to display results as you see fit

$t++;
print '<td align="center">';
print "<a href=\"" .$data['link']."\" title=\"Add An Image - Link No. ".$data['linknum']."\"><img src=\"phpThumb.php?src=" .$data['link']. "&w=100\"></a><br>";
print "submitted by<br>";
print $data['name']."<br>";
print $data['date_entered']."<br>";
print '</td>';

if ($t == 5) {
print '</tr>';
$t=0;
}
}
print '</table>';

print '<p align="center">';

// next we need to do the links to other results

if($offset >= $limit){
$newoffset=$offset-$limit;
print "<a href=\"$PHP_SELF?catagory=$catagory&offset=$newoffset\">PREV</a> ";
}

// calculate number of pages needing links
$pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}

for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
if ($newoffset != 0){
print "<a href=\"$PHP_SELF?catagory=$catagory&offset=$newoffset\">$i</a> &nbsp; \n";
}
}

// check to see if last page
if($numrows-$offset > $limit){
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?catagory=$catagory&offset=$newoffset\">NEXT</a>\n";
}
print '</p>';
?>

Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vim function to generate RTL Code(finite state machine) in verilog

Hi I wanted to call the AutoFsm function (given below) in vim to generate a code something like: **********verilog code to generate ************* always @(posedge clk or negedge rst_n) begin if(!rst_n) begin state_r <= #1 next_stateascii_r; ... (0 Replies)
Discussion started by: dll_fpga
0 Replies

2. UNIX for Advanced & Expert Users

Limit on amount of lines less can handle

Is there a limit on the amount of lines less can handle? I grepped for something that is pretty common in my files so I tried to filter it through less so it was easier to look at. So I then used a redirect ">" to create a file. It created a file that was 103K long. So that makes me think there is... (6 Replies)
Discussion started by: cokedude
6 Replies

3. UNIX for Dummies Questions & Answers

Match the amount fields in the source file vs trigger file

Hello, I have to write a script to compare the sum of the amount fields in a source file and the amount field in another file. details are: based on the name of the source file (say SALES as an example), a file already available in a path will be grabbed (say SALES_ParmFile) and this file... (4 Replies)
Discussion started by: vijaylak
4 Replies

4. UNIX for Dummies Questions & Answers

outputting set -x to file

I need to enable set -x in my croned script as at times the script is not returning all data that it should be. This only happens intermittently and as such I would like a means of being able to check what goes wrong. My question is how to output the debug of set -x to file? (1 Reply)
Discussion started by: rob171171
1 Replies

5. Shell Programming and Scripting

Finding several patterns and outputting 4 lines after

I an trying to parse a file looking for pattern1, or pattern2, or pattern3 and when found print that line and the next 4 lines after it. I am using korn shell script on AIX and grep -A isn't available. (1 Reply)
Discussion started by: daveisme
1 Replies

6. Shell Programming and Scripting

Outputting discarded GREP lines to a file

I had a question about grep. If I grep for something in a file, the output shows me all the lines in which that 'something' is contained in. Is there a way to also output all the lines in which that 'something' wasnt contained in. Say I have a file with a bunch of names and I do: grep scott... (2 Replies)
Discussion started by: ndedhia1
2 Replies

7. Shell Programming and Scripting

Outputting data from multiple lines

Hi guys, looking for a bit of advise, and as I am a complete novice, please excuse the daft questions!! I have a list of events and of which entry looks like this; # # Event 1 # NAME = Event 1 # 12345 : 123 : 1 : 1 : L,1,N : 1,0 : Event # # Event 2 # NAME = Event 2 # 12346... (8 Replies)
Discussion started by: JayC89
8 Replies

8. Shell Programming and Scripting

Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in 1) starting with "20071126 11:11:11 Machine Header 1" 1000 lines... "End machine header 1" 2) starting with "20071126 12:12:12 Machine... (5 Replies)
Discussion started by: vikas.iet
5 Replies

9. Shell Programming and Scripting

Problem with outputting multiple lines

Dear Gurus, I have this output file: F1BDEV13 NTIAF101 2006/09/21 14:54:51 14:55:29 1 0560-0570 LAN F1BDEV14 NTIAF101 2006/09/21 14:55:30 14:55:49 1 0000-0000 LAN F1FSP001 NTIAF101 2006/09/21 14:55:51 14:55:53 1 0000-0000 LAN F1NSP001 ... (6 Replies)
Discussion started by: lweegp
6 Replies

10. Shell Programming and Scripting

deleting a varying amount of lines from a list of files

I did search the posts for info on this and while there were some in the ballpark, none addressed this specifically. (also I tried to post this once it said I was logged out, so hopefully I'm not sending a duplicate here). I have a set of files (250 +/-) where I need to delete the first "$x"... (4 Replies)
Discussion started by: benair
4 Replies
Login or Register to Ask a Question