![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Outputting formatted Result log file from old 30000 lines result log<help required> | vikas.iet | Shell Programming and Scripting | 5 | 12-02-2007 07:43 PM |
| Problem with outputting multiple lines | lweegp | Shell Programming and Scripting | 6 | 09-22-2006 10:04 AM |
| deleting a varying amount of lines from a list of files | benair | Shell Programming and Scripting | 4 | 04-14-2006 10:48 AM |
| need help appending lines/combining lines within a file... | mr_manny | Shell Programming and Scripting | 2 | 01-06-2006 03:45 PM |
| sed not outputting last line of input file | 2reperry | Shell Programming and Scripting | 3 | 12-16-2005 09:51 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
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, Last edited by pondlife; 10-11-2005 at 08:44 AM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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> \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>'; ?> |
|||
| Google The UNIX and Linux Forums |