Page 1 of 2

PHP pagination

Posted: Tue Jul 31, 2007 11:37 pm
by akimm
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.

sortable javascript

Posted: Tue Jul 31, 2007 11:45 pm
by yacahuma

Posted: Tue Jul 31, 2007 11:46 pm
by akimm
Thanks!!! I'm going there now.

Posted: Wed Aug 01, 2007 8:32 am
by akimm
Would it work better if I made each journal seperate then used count function or another function to read how many journal entries there were, and print some set number per page?

Posted: Wed Aug 01, 2007 9:36 am
by akimm
here is what I got so far..

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);
}
?>

Posted: Fri Aug 03, 2007 9:49 pm
by akimm
Any ideas guys?

Posted: Fri Aug 03, 2007 10:15 pm
by SidewinderX
Why not store your journal entries in XML format? I'm sure it would be easier to modify, manage, and sort. I know the Java-DOM functions has the ability to count how many XML entities there are, and loop through them. I'm sure PHP XML parsers have just as much, if not more functionality...

Posted: Fri Aug 03, 2007 10:41 pm
by akimm
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?

Posted: Sat Aug 04, 2007 7:29 am
by superdezign
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?
You could create an extremely simplistic one.

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>
I'm sure that you can see how easy it is to manipulate.

That seems simple enough

Posted: Sat Aug 04, 2007 9:36 am
by akimm
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.

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

Posted: Sat Aug 04, 2007 9:47 am
by akimm
A better question might be.

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

Posted: Sat Aug 04, 2007 9:54 am
by superdezign

Posted: Sat Aug 04, 2007 10:01 am
by akimm
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?

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>

Posted: Sat Aug 04, 2007 10:02 am
by superdezign
akimm wrote: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?
Could you please stop asking questions and just write the code, already?

Posted: Sat Aug 04, 2007 10:04 am
by akimm
Sorry. I didn't realize I was being a bother. I will try and write it now.