PHP pagination

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!

Moderator: General Moderators

User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

akimm wrote:Sorry. I didn't realize I was being a bother. I will try and write it now.
The "bother" was that you were asking without trying.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

read_journal.xml
<CATALOG>
&#8722;
	<journal>
<content><?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);
}
?>
</content>
</journal>
&#8722;

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="journal_read.xml" id="xmldso" async="false"></xml>

<p>
Title:
<span datasrc="#xmldso" datafld="CONTENT"></span>
<br />
</p>
<p>
<input type="button" value="previous entry"
onclick="moveprevious()" />
<input type="button" value="Next entry"
onclick="movenext()" />
</p>
</body>
</html>
Probably incorrect, but I want the php to print in that form if it can, because as of now the php reads directly from the files, in the format I want them to be.

I could adjust the journal to be strictly XML if the above is impossible.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

XML pros any help?

Post by akimm »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


here is the form

Code: Select all

<form action="journalbox.php" method="POST"><p><b>Date</b><input type="text" value="<b><?php echo date('F j, Y, g:i a');?></b>" name="date" size="30"></p><p><b>Mood</b>

<select name="mood"><option value="apathetic">apathetic<option value="overjoyed">overjoyed<option value="inquisitive">inquisitive<option value="outlandish">outlandish<option value="appreciative">appreciative<option value="confused">confused<option value="displeased">displeased<option value="disgruntled">disgruntled<option value="sick">sick<option value="terrified">terrified<option value="mental">mental<option value="eruditic">eruditic<option value="forlorn">forlorn<option value="convuluted">convuluted<option value="ingenious">ingenious<option value="arrogant">arrogant<option value="free">free<option value="stupid">stupid<option value="moronic">moronic<option value="pointless">pointless</select><br /><br />
<select name="smile">
<?php 

$files = glob("smile/*.gif"); 
##Display $files  

foreach ($files as $key => $value) 
{ 
    echo '<option value="' . $value. '">' . $value . '</option>'; 
} 
?>
</select> 
<p><b>entry</b><TEXTAREA NAME="entry" COLS="80" ROWS="5" WRAP="virtual"></TEXTAREA></P><p><input type="submit" name="submit" value="send your entry!"></p></form>
here is the file I have writing to journal/ the directory for all journal entries.

Code: Select all

<?php
##this journal, mood, smile, body, & entry are an effort to write to files in XML format
$write_string = "<journal>";
$write_string .= "<date>";
$write_string .= "<b>" . "<font color=#006699>" . "Date posted:  " . 

"</font>" . "</b>" . $_POST['date'];
$write_string .= "</date>"; 
$write_string .= "<mood>";
$write_string .= "<font family=arial>"; $write_string .= "<BR>" . 

"<BR>";
$write_string .= "<b>" . "<font color=#006699>" . "Current mood:  " . 

"</font>"   . "</b>" . $_POST['mood'];
$write_string .= "</mood>";
$write_string .= "<smile>";
$write_string .= "<font family=arial>";
$write_string .=  "<img src=" . $_POST['smile'] . ">" . "<br>" . 

"<br>" . "<br>";
$write_string .= "</smile>";
$write_string .= "<entry>";
$write_string .= stripslashes($_POST['entry']) . "<font family=arial>" 

. "<BR>" . "<BR>";
$write_string .= "</entry>";
$write_string .= "<HR NOSHADE SIZE=4 COLOR=BLUE>";
$write_string .= "</journal>";

$fp = fopen( 'journal/' . $_POST['mood'] . rand(1, 1000) . '.xml', 

'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>
here is the file that reads and prints the XML documents from /journal to my page journal.php

Code: Select all

<?php
error_reporting (E_ALL);
$path = "journal/";
foreach(glob($path . "*.xml") as $file) {
$fh = fopen($file, 'r');
$theData = fread($fh, filesize($file));
echo $theData;
fclose($fh);
}
?>
Thats about it for now, I am trying an XML solution because once I get this properly formatted another member kindly suggested XML due to its abilities. What I want to do is take 5-8 seperate XML documents and print them per page. And then send the rest to another page.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

here is my latest try, all the other codes at least brought back the journal w/out errors. I modified this code from zend. Any suggestions?

journalbox -> file that writes from form.php to my directory journal/

Code: Select all

<?php
$write_string = "<?xml version='1.0' encoding='iso-8859-1' ?>";
$write_string .= "<journal>";
$write_string .= "<date>";
$write_string .= $_POST['date'] . "</date>";
$write_string .= "<mood>" . $_POST['mood'] . "</mood>";
$write_string .= "<smile>" . "<img src=" . $_POST['smile'] . ">" . 

"</smile>";
$write_string .= "<entry>" . stripslashes($_POST['entry']) . 

"</entry>" . "</journal>";

$fp = fopen( $_POST['mood'] . rand(1, 1000) . '.xml', '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>
This is the code that reads the XML, incorrectly as of now.

Code: Select all

<?php

##variables
$path = "journal/";
foreach(glob($path . "*.xml") as $file) {
$fh = fopen($file, 'r');
$parser = xml_parser_create;
xml_parse($parser, $file);
?>
<html>
  <body>
<?php


?>
 </body>
</html>
<?php
/* load the xml file and stylesheet as domdocuments */
$xsl = new DomDocument();
$xsl->load("journal.xsl");
$inputdom = new DomDocument();
$inputdom->load($file);

/* create the processor and import the stylesheet */
$proc = new XsltProcessor();
$xsl = $proc->importStylesheet($xsl);
$proc->setParameter(null, "titles", "Titles");

/* transform and output the xml document */
$newdom = $proc->transformToDoc($inputdom);
print $newdom->saveXML();
   }
  // close after printing
  fclose($fh);
  xml_parser_free($parser);
?>

here is the XSL file which I want to format the xml

Code: Select all

<?xml version=”1.0”?>
<xsl:stylesheet version=”1.0” xmlns:xsl=http://www.w3.org/1999/XSL/Transform>

  <xsl:template match=”/”>
  <html>
  <head><title>Sean's Journal</title></head>
  <body>
  <xsl:apply-templates />
  </body>
  </html>
  </xsl:template>

  <xsl:template match=”/journal”>

  <xsl:for-each select=”journal”>
  date: <b><xsl:value-of select=”date” /></b><br />
  current mood: <b><xsl:value-of select=”mood” /></b> <br />
  <xsl:value-of select=”smile” /><br />
  <xsl:value-of select=”entry” />
  </xsl:for-each>

  </xsl:template>

  </xsl:stylesheet>
THANKS for anyone who can help, I have been trying to find a solution for this thing for some time now. Thanks.
Post Reply