zero-perfoliate
zero-perfoliate

Author Topic: I have an intresting question  (Read 480 times)

Offline blackhawkso

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
I have an intresting question
« on: May 25, 2010, 04:29:23 PM »
I have a site i have been building using php and mysql their is a section that the poet that i am building the site for want's to display his new work. What i have at the moment can been seen here http://www.richardbonfield.com/pages/work.php what the poet wants thought is insted of scrolling he wants the poem to continue on the next page. I was thinking is their a way i could count the amount of lines their is then tell the script to split the text at say line 20 and then show from line 21 on the right hand page. All the poems are stored in the database and the poet enters them himself via a php form in an admin section and as if that aint bad enought if the poem is shorter than say 20 lines the code needs to know to show the next poem on the right hand page. Can this be done?? Please help

Offline josh.legogeek

  • PHP Workers
  • **
  • Posts: 5
  • Karma: +0/-0
Try this.
« Reply #1 on: June 07, 2010, 12:40:06 PM »
This may help.
This implies that the lowest id in the db is the newest.
Just write the code to get the poem from the db by id and the code to show it (possibly on the next page).
Then call poem(); and it will do the work.
It will return false if the poem it got a bad number from strlen(); or if the poem is empty.
It will return 3 if it showed two poems, or 4 if it showed one and continued.
I hope this helps you!
Code: [Select]
<?php
function getpoem($id=1)
{
//Code to get poem and return it
}
function 
showpoem($poem,$continueonnextpage=false)
{
//Code to show poem (and possibly continue on next page)
}
function 
poem($id=1)
{
$length1 strlen(getpoem($id));
if (
$length<=20&&$length!==0)
{
showpoem(getpoem());
showpoem(getpoem(2));
return 
3;
}
elseif (
$length>20)
{
showpoem(getpoem(),true);
return 
4;
}
else
{
return 
false;
}
?>