PHP pagination
Moderator: General Moderators
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
PHP pagination
I have a text document that I use simple fopen,fread,frwrite functions for a journal I keep myself. I was wondering, do you think its practical to have the page after a certain amount of characters paginate, or is there anything I might not know to help cut off at a certain point? I just mean after say, 5 entries it adds all new entries to page 2.
I was thinking maybe* to use a counter, everytime I add an entry have the form iterate, until it reaches X number and then paginates. Any ideas you can bounce off me is more than appreciated, I will start some code once I figure out which way is the best way to tackle this prob.
I was thinking maybe* to use a counter, everytime I add an entry have the form iterate, until it reaches X number and then paginates. Any ideas you can bounce off me is more than appreciated, I will start some code once I figure out which way is the best way to tackle this prob.
- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
here is what I got so far..
I need it to read from that directory using glob( "*.txt") perhaps, I want it to read a set number of files then print them to the first page, redirect all the others to the next page and continue the process so as to keep each page limited in its journal entries
here is what I have with the glob idea used, any way to limit or direct only a certain amount of entries with glob????
Code: Select all
<?php
## this program takes form info and writes it to my directory journal/
$write_string = "<b>" . "<font color=#006699>" . "Date posted: " . "</font>" . "</b>" . $_POST['date'];
$write_string .= "<font family=arial>"; $write_string .= "<BR>" . "<BR>";
$write_string .= "<b>" . "<font color=#006699>" . "Current mood: " . "</font>" . "</b>" . $_POST['mood'];
$write_string .= "<font family=arial>";
$write_string .= "<img src=" . $_POST['smile'] . ">" . "<br>" . "<br>" . "<br>";
$write_string .= stripslashes($_POST['entry']) . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";
$fp = fopen( 'journal/' . $_POST['mood'] . rand(1, 10) . '.txt', 'w');
if($fp) {
fwrite($fp, $write_string);
fclose($fp);
}
?>
<h1>Sucessfully posted</h1>
<br><br>
<?php
echo "<b>" . "<font color=#006699>" . "Date posted: " . "</font>" . "</b>" . $_POST['date'] . "<br>";
echo "<b>" . "<font color=#006699>" . "Current mood: " . "</font>" . "Current Mood: " . "</b>" . $_POST['mood'] . "<br>";
echo "<img src=" . $_POST['smile'] . ">". "<br>" . "<br>" . "<br>";
echo stripslashes($_POST['entry']) . "<br>";
?>
<br><br>
<a href="http://www.akimm.com/journal06/journal.php">Go To Journal Sean!</a>I need it to read from that directory using glob( "*.txt") perhaps, I want it to read a set number of files then print them to the first page, redirect all the others to the next page and continue the process so as to keep each page limited in its journal entries
here is what I have with the glob idea used, any way to limit or direct only a certain amount of entries with glob????
Code: Select all
<?php
error_reporting (E_ALL);
$path = "journal/";
foreach(glob($path . "*.txt") as $file) {
$fh = fopen($file, 'r');
$theData = fread($fh, filesize($file));
echo $theData;
fclose($fh);
}
?>-
SidewinderX
- Forum Contributor
- Posts: 407
- Joined: Fri Jul 16, 2004 9:04 pm
- Location: NY
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
You could create an extremely simplistic one.akimm wrote:how would I go about doing that. I've never used XML, but wouldn't mind trying it. Am I going to need to write the DOM?
Code: Select all
<journal>
<entry>
<title>
Journal Entry #1
</title>
<content>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse....
</content>
</entry>
<entry>
<title>
Journal Entry #2
</title>
<content>
........
</content>
</entry>
</journal>- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
That seems simple enough
Will google tell me how to actually take all that xml data and loop it like I want to. Because as of now I have all my entries being written directly to the directory. Can I possibly have the XML formatted through the fwrite process? Like for instance. Here is my code to post my entries now.
Is it possible to $_POST it in XML format then use XML to print each entry, then do I need an external DOM or do I invoke a parser, what do I do to tell the page to act like XML?
Code: Select all
<?php
$write_string = "<b>" . "<font color=#006699>" . "Date posted: " . "</font>" . "</b>" . $_POST['date'];
$write_string .= "<font family=arial>"; $write_string .= "<BR>" . "<BR>";
$write_string .= "<b>" . "<font color=#006699>" . "Current mood: " . "</font>" . "</b>" . $_POST['mood'];
$write_string .= "<font family=arial>";
$write_string .= "<img src=" . $_POST['smile'] . ">" . "<br>" . "<br>" . "<br>";
$write_string .= stripslashes($_POST['entry']) . "<font family=arial>" . "<BR>" . "<BR>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";
$fp = fopen( 'journal/' . $_POST['mood'] . rand(1, 1000) . '.txt', 'w');
if($fp) {
fwrite($fp, $write_string);
fclose($fp);
}
?>
<h1>Sucessfully posted</h1>
<br><br>
<?php
echo "<b>" . "<font color=#006699>" . "Date posted: " . "</font>" . "</b>" . $_POST['date'] . "<br>";
echo "<b>" . "<font color=#006699>" . "Current mood: " . "</font>" . "Current Mood: " . "</b>" . $_POST['mood'] . "<br>";
echo "<img src=" . $_POST['smile'] . ">". "<br>" . "<br>" . "<br>";
echo stripslashes($_POST['entry']) . "<br>";
?>
<br><br>
<a href="http://www.akimm.com/journal06/journal.php">Go To Journal Sean!</a>- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
A better question might be.
Can I take this code, and plug in the php right into it? Then use XML to sort the amount of entries on each page?
Code: Select all
<journal>
<entry>
<title>
Journal Entry #1
</title>
<content>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse....
</content>
</entry>
<entry>
<title>
Journal Entry #2
</title>
<content>
........
</content>
</entry>
</journal>- akimm
- Forum Contributor
- Posts: 460
- Joined: Thu Apr 27, 2006 10:50 am
- Location: Ypsilanti Michigan, formally Clipsburgh
hey, I found this code on w3s
Obviously I would adjust it a bit, but do you think this could be suitable for my purpose?
Obviously I would adjust it a bit, but do you think this could be suitable for my purpose?
Code: Select all
<html>
<head>
<script type="text/javascript">
function movenext()
{
x=xmldso.recordset
if (x.absoluteposition < x.recordcount)
{
x.movenext()
}
}
function moveprevious()
{
x=xmldso.recordset
if (x.absoluteposition > 1)
{
x.moveprevious()
}
}
</script>
</head>
<body>
<xml src="cd_catalog.xml" id="xmldso" async="false"></xml>
<p>
Title:
<span datasrc="#xmldso" datafld="TITLE"></span>
<br />Artist:
<span datasrc="#xmldso" datafld="ARTIST"></span>
<br />Year:
<span datasrc="#xmldso" datafld="YEAR"></span>
</p>
<p>
<input type="button" value="Previous CD"
onclick="moveprevious()" />
<input type="button" value="Next CD"
onclick="movenext()" />
</p>
</body>
</html>- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm