SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    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>");}

  2. #2
    SitePoint Evangelist
    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>

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    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?

  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    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

  5. #5
    SitePoint Evangelist
    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 ?

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    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?

  7. #7
    <? echo "Kick me"; ?> petesmc's Avatar
    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

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    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>

  9. #9
    SitePoint Evangelist
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •