SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
Thread: Split up results
-
Jan 6, 2001, 07:16 #1
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How would you split text up over multiple page using PHP/MySQL.
I read the article by Kevin Yank and couldn't figure out how to split up text.
If you are splitting up text:
Do you ::::
$result = mysql_query("Select blah from balh " .
"where blah=$blah");
// THE BELOW LINE GIVES A PARSE ERROR
$result = mysql_fetch_array($result);
$text = $result["Text"]
if (!isset($page)) $page = 0;
$textarray=split("\[PAGEBREAK]",$text);
$text=$textarray[$page];
if ($page != 0) {
$prevpage = $page - 1;
echo("<P><A HREF=\"$PHP_SELF?aid=$aid&page=$prevpage\">".
"Previous Page</A></P>");}
echo( "<P>$text" );
if ($page < count($textarray) - 1) {
$nextpage = $page + 1;
echo("<P><A HREF=\"$PHP_SELF?aid=$aid&page=$nextpage\">".
"Next Page</A></P>");}
-
Jan 6, 2001, 07:20 #2
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think to fix your parse error,
$text = $result["Text"];
Okay.. I think I know what you are trying to do
a) use explode. Split is designed for regexps, so will be alot slower.
$textarray=explode("[PAGEBREAK]",$text);
Other than that, it looks about right.. are you getting any other specific errors?
<Edited by PeterW on 01-06-2001 at 07:27 AM>
-
Jan 6, 2001, 07:24 #3
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry, i was writing fast, that meant to be there.
From what ican see, to make a page split, while entering into databswe i must add the words [PAGEBREAK] when i want the page to split. Am i right?
-
Jan 6, 2001, 07:30 #4
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code i use:
---------
<?php
include("articles.inc");
$result = mysql_query("SELECT Text FROM articles WHERE AID=$aid");
$result = mysql_fetch_array($result);
$text = $result["Text"];
if (!isset($page)) $page = 0;
$textarray=split("\[PAGEBREAK]",$text);
$text=$textarray[$page];
if ($page != 0) {
$prevpage = $page - 1;
echo("<P><A HREF=\"$PHP_SELF?aid=$aid&page=$prevpage\">".
"Previous Page</A></P>");}
echo( "<P>$text" );
if ($page < count($textarray) - 1) {
$nextpage = $page + 1;
echo("<P><A HREF=\"$PHP_SELF?aid=$aid&page=$nextpage\">".
"Next Page</A></P>");}
?>
--------
Error i get:
Warning: Supplied argument is not a valid MySQL result resource in /home/petesmc/public_html/page.php on line 11
-
Jan 6, 2001, 07:30 #5
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes, the page will break when you have [PAGEBREAK] in the text. You have to type this in when you type up your articles. But, you could have your "articles submission script" cut it after a paragraph after a certain amount of characters.
"Warning: Supplied argument is not a valid MySQL result resource in /home/petesmc/public_html/page.php on line 11" is probably because you haven't connected to mysql ?
-
Jan 6, 2001, 07:35 #6
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have, articles.inc, should i do a pconnect?
-
Jan 6, 2001, 07:38 #7
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thankyou very much, i actaully didn't connect to the databse. Thankyou
That solves everything.
Soo...Much
-
Jan 6, 2001, 08:18 #8
- Join Date
- Nov 2000
- Location
- Hong Kong
- Posts
- 1,508
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
One more question though, if i am doing a print template, how do i mmake PHP remove the words [PAGEBREAK] from the text?
And how would i add something to the LAST page only?
<Edited by petesmc on 01-06-2001 at 08:21 AM>
-
Jan 6, 2001, 09:04 #9
- Join Date
- Jul 2000
- Location
- Warwickshire, England
- Posts
- 557
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$text = str_replace ("[PAGEBREAK]", "", $text);
easy way to do something extra for last page...
find this part..
if ($page < count($textarray) - 1)
{
$nextpage = $page + 1;
echo("<P><A HREF=\"$PHP_SELF?aid=$aid&page=$nextpage\">".
"Next Page</A></P>");
}
and add
else
{
echo ("this is the last page");
}
Bookmarks