SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am looking for the code that will allow me to split up my articles into "pages". I have searched the Forums and I can only find incomplete chunks of the code that I want to use. Would someone mind posting the full code itself or a link to the code?

    cheers
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is a fairly broad request. How are the articles being stored in the database?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry all. The articles are being stored in a DB in one large field.

    id
    title
    heading (must appear at the top of every page)
    body (the actual article)
    date
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That will be pretty tough to do, and make it look nice. Maybe if you were to put some sort of delimiter in the article itself where the atricle should be broken like [newpage] to separate the pages, you could take the article split it on [newpage].

    if(!isset($page)) $page = 0;
    $articletext = explode("[newpage]", $articletext);
    print $articletext[$page];


    This would print the first page and then you would need links like I showed you before to make the next / prev links

    for the next link
    if ($page != (count($articletext) - 1)) {
    printf('<a href="%s?page=%s">next &gt;&gt;</a>', $PHP_SELF, $page + 1);
    }

    for the prev link
    if ($page != 0) {
    printf('<a href="%s?page=%s">prev &lt;&lt;</a>', $PHP_SELF, $page - 1);
    }
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy...I was planning on having a delimiter in the text. I don't have it yet, but I can set that up no sweat.

    SO, I would do my query just like normal and then use the snippet of code you gave me to split it up and print it out?

    ok...for somereason I thought there was a lot more to it. What about a custom piece of text for the "next" and "previous" links? I have seen some people askign for that and that sounds like it might be a cool thing.
    <Edited by creole on 01-19-2001 at 01:36 PM>
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What exactly do you mean custom piece of text?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean letting me customize what the link will say that's all. Instead of ever page having "next page" and "previous" page, let me define the text say in the article itself.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That will be a little bit trickier since you are not storing chapters you could put a page title in brackets say right after the [newpage]

    something like sdljsdfkskdf l;sfjk ;lfsdkg [newpage][How to fly fish]dafjdfj slfjd sf glksflk sfl


    Try this


    <?
    $str = "[First Page]fjkhsfkdjhgskdfj hsfjkhg sfkjhkjsdf hkjsdfhg jkhgs kljhdfzsgjk hdfjkg h[newpage][Page 2]dhfgsdkjf sjkdfhsjkdhf sdjkfh khfkasdjh ksfjahg kjsdfahg sda[newpage][Page 3]sd;fgjsdfl; gjkdf;ljkg l;fdkj lf;xdk fl;skg sl;fk";
    if (!isset($page)) $page = 0;

    $text = explode("[newpage]", $str);
    print substr($text[$page], strpos($text[$page], "]") + 1, strlen($text[$page]));
    print '<p><p>';


    if ($page != 0) {
    printf('<a href="%s?page=%s">%s</a>', $PHP_SELF, $page - 1, substr($text[$page - 1], strpos($text[$page - 1], "[") + 1, strpos($text[$page - 1], "]") - 1));
    }
    print "<br>";

    if ($page != (count($articletext) - 1)) {
    printf('<a href="%s?page=%s">%s</a>', $PHP_SELF, $page + 1, substr($text[$page + 1], strpos($text[$page + 1], "[") + 1, strpos($text[$page + 1], "]") - 1));
    }



    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by chapters, you mean breaking the story up into "paragraphs"? Well, I am not doing that because the storyies for the most part are only about 2 pages long. I will put the [newpage] breaks about every 3-4 paragraphs.
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  10. #10
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NO I am just saying that you could put whatever you want the links to say in brackets right after [newpage] like I have in my example, it doesn't ahve to mean chapters just a label for the links. Does that make sense?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  11. #11
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  12. #12
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So then what is your question exactly?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  13. #13
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats what i did:

    I have:

    [PAGEBREAK] which splits up the page, then after a page break, anything before the first: | is considered a title and anything after the first: | is a chapter. After the second | is the content.

    It works great for me....

    Peter

  14. #14
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well...for right now, I will forgo having titles as I didn't quite understand the code there...

    This is the winner for me...

    while ($row = mysql_fetch_array($result)) {
    echo $row["heading"];
    if(!isset($page)) {
    $page = 0;
    } else {
    $page = $page;
    }
    $articletext = explode("[newpage]", $row["body"]);
    print $articletext[$page];
    echo "<br><br>";
    }

    print "<div align=\"center\">";

    // for the prev link
    if ($page != 0) {
    printf('<a href="show_news.php3?id=%s&page=%s" class="mainpage">&lt;&lt;&lt;Previous Page</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $id, $page - 1);
    }

    // for the next link
    if ($page != (count($articletext) - 1)) {
    printf('<a href="show_news.php3?id=%s&page=%s" class="mainpage">Next Page&gt;&gt;&gt;</a>', $id, $page + 1);
    }

    print "</div>";
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  15. #15
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a small tip Andy you don't need to assign $page to $page like below if page isn't set then it gets set to 0 if it is set then you don't need to reassign it.

    if(!isset($page)) {
    $page = 0;
    } else {
    $page = $page;
    }


    This can be written as

    if(!isset($page)) {
    $page = 0;
    }

    Or for efficiency's sake
    if(!isset($page)) $page = 0;



    What part about the other code do you not understand basically after you split the page up you will have a certian number of elements in the array $articletext

    if each element started with [some link text] then the text you could take whatever was in those brackets and put it in the link and then just print out the rest of the text




    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  16. #16
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll give it a try a bit later...right now I have my hands full just breaking the articles down into bite size chunks.

    thanks again Freddy...

    I think that I am going to have put that line into my signature...lol
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes


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
  •