Page 1 of 1

Automatic page adding

Posted: Wed Dec 22, 2004 1:27 pm
by andylyon87
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.

Code: Select all

<?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");
}
?>
The end result can be found here: http://www.nero-publications.co.uk/fall ... p?id=guest

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. :?


Thanks guys

Posted: Wed Dec 22, 2004 1:30 pm
by onion2k
Its called 'pagination'. Theres a lot of tutorials kicking about. Try google, or if you fancy it read the article I wrote about it: http://www.ooer.com/index.php?section=php&id=10

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.

Posted: Wed Dec 22, 2004 1:37 pm
by markl999
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
..which is a nice shortcut.
See http://dev.mysql.com/doc/mysql/en/Infor ... tions.html for more info.

Posted: Wed Dec 22, 2004 1:42 pm
by andylyon87
Cheers guys will look it up and post back if I have any probs, wasnt sure of the technical term so thanks

Posted: Wed Dec 22, 2004 3:51 pm
by mohson
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!!!!