PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Is there any way of making the content of a file split over a number of pages, I have a guestbook on a site and wondered if I could say after the 20th entry got to a page 2 and have 20 per page.
Below is the way in which the text is read, the text is retrieved from a txt file declared in the first couple of results.
<?php
$guest_file="php/form_data/guestbook.txt";
$pointer=fopen($guest_file,"r");
$lines_array=file($guest_file);
fclose($pointer);
$lines_array=array_reverse($lines_array);
print("
<center><TABLE CELLPADDING=3 CELLSPACING=0 BORDER=0 WIDTH=450>
<TR><TD>Welcome to the guestbook this is where you guys have your say about the band and the site.<BR> <a href=?id=guest_add>[Add Entry]</A> <A href=?id=guest_remove>[Remove Entries]</A><BR><BR>
</TR>");
for($i=0; $i<count($lines_array); $i++) {
$lines=count($lines_array);
$line_array=explode("¡",$lines_array[$i]);
$date=$line_array[0];
$name=$line_array[1];
$news=$line_array[2];
$view=$line_array[3];
print("
<center><TABLE CELLPADDING=3 CELLSPACING=0 BORDER=0 WIDTH=450>
<TR><TD bgcolor=E0E0E0><FONT COLOR=#484848><B>$date</B> by <B>" .ucfirst($name). "</B></TD></TR>
<TR><TD VALIGN=TOP CLASS=JUSTIFY><FONT COLOR=#717171>$news</TD></TR>
<TR><TD VALIGN=TOP class=footer><I># " .(($lines-$i)-1). "</I></TD></TR>
</TABLE>\n<BR>\n");
}
?>
Please help if you can any thoughts are welscome thanks, this is in the prototype stages and is an upgrade from the bands current and very nasty bravenet message board.
PS. What is about female drummers? Theres some unwritten law that says they all have to be foxy or something.. The drummer in the Corrs, the Donnas, the Eyeliners, the Sahara Hotnights.. and now this Kat too. Bizarre.
Last edited by onion2k on Wed Dec 22, 2004 1:37 pm, edited 1 time in total.
Just thought i'd add this here as it's pagination related.
When doing pagination you need to get the total number of pages as well as select the records for the current page, which involves 2 queries. With recent versions of MySQL there's a handy FOUND_ROWS() function:
A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To get this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, then invoke FOUND_ROWS() afterward
An advance warning - IM a complete newbie to PHP but it took me 3 weeks to crack it - I put posts on here time after time after time and got good advice.
My one bit of advice is this if you get code snippets or people tell you how to do it or how they do it make sure u take your time before choosing a route cos trust me there is hundreds of ways of doding it!!!!