SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  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)
    I call an artile from a table and split it up into pages using the tag [PAGEBREAK] - Just for the record.

    I was wondering, since a whole article,n o matter how many pages, if in one record in a table then could i put something like this on every page i want:

    [SUBTITLE="Subtitle here"]

    Then later, i could call the subtitle and display it between:
    <h1> and </h1>

    and i could display it in my next buttons.

    Question is, how could i do this and would i be able to call every instant of this throughout the whole document and display it into a select box like sitepoint does in its articles?

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, is it better to have a seperate record for each page of an article or better to have one record and just split the pages up?

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think, assuming you're a beginner or intermediate, it makes the most sense to store the entire article in the database...but I could be wrong.

    I asked this same question awhile ago:
    http://www.sitepointforums.com/showt...threadid=14141

    Hope that helps.

  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)
    I am guessing that this is what you are refering to..


    I'll be assuming you use [pagebreak]Title[/pagebreak] to break pages. You may adjust regexps if you wish...

    To get the task done, you'll make each [pagebreak] somewhat like a header on each page, i.e. you'll split pages right before the pagebreak tags.



    code:--------------------------------------------------------------------------------# Create a temporary token to ensure the pages split correctly
    $articletext = eregi_replace('(\[pagebreak][^[]+\[/pagebreak])', '!!!TEMP-TOKEN!!!\\1', $articletext);

    # Split on !!!TEMP-TOKEN!!!, leaving [pagebreak]s
    $pagestemp = split('!!!TEMP-TOKEN!!!', $articletext);

    # Add a title to the 1st page
    $pagestemp[0] = '[pagebreak]Introduction[/pagebreak]' . $pagestemp[0];
    --------------------------------------------------------------------------------

    Now, to retrieve the title for a given page, use this code:


    code:--------------------------------------------------------------------------------# Find the [pagebreak] tags and capture title inside them
    eregi('\[pagebreak]([^[]+)\[/pagebreak]', $pagestemp[$pagenumber], $pagenametemp);

    # Get captured title
    $pagename = $pagenametemp[1];
    --------------------------------------------------------------------------------

    Substitute $pagenumber on the first line by the number of the page (start counting from 0). In particular, use a formula involving $pid to get next / prev pages...

    Okay, i am really cofused, well here is my previous code:

    Code:
    if (!isset($page)) $page = 0; 
    $textarray=explode("[PAGEBREAK]",$text); 
    $text=$textarray[$page]; 
    echo( "<font size='2'><P>$text</p></font>" ); 
    
    // NEXT AND PREVIOUS PAGE LINKS
    if ($page != 0) { 
    $prevpage = $page - 1; 
    echo("<A HREF=\"$PHP_SELF?aid=$aid&page=$prevpage\">". 
    "Previous Page</A>&nbsp;&nbsp;");} 
    
    
    if ($page < count($textarray) - 1) { 
    $nextpage = $page + 1; 
    echo("&nbsp;&nbsp;<A HREF=\"$PHP_SELF?aid=$aid&page=$nextpage\">". 
    "Next Page</A>");}

    help greatly appreciated...

  5. #5
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, here is my code, adding what i needed. Except, it doesn't split pages or add titles:

    <?php
    echo("<font size='1'><a href='print.php?aid=$aid'>Print this Article</a></font><br><br>");
    echo("<font size='6'>$title</font><br><font size='1' color='#0099FF'>by $name</font><br><br>");
    if (!isset($page)) $page = 0;
    // TEMPORARY TOKEN TO MAKE SURE SPLIT WORKS
    $text = eregi_replace('(\[pagebreak][^[]+\[/pagebreak ])', '!!!TEMP-TOKEN!!!\\1', $text);
    // SPLIT
    $pagestemp = split('!!!TEMP-TOKEN!!!', $text);
    // TITLE FIRST PAGE
    $pagestemp[0] = '[pagebreak]Introduction[/pagebreak]' . $pagestemp[0];
    // GET TITLE FROM TAGS
    eregi('\[pagebreak]([^[]+)\[/pagebreak]', $pagestemp[$pagenumber], $pagenametemp);
    //GET TITLE
    $pagename = $pagenametemp[$page];
    echo $pagename;
    echo( "<br><br><font size='2'><P>$text</p></font>" );

    // NEXT AND PREVIOUS PAGE LINKS
    if ($page != 0) {
    $prevpage = $page - 1;
    echo("<A HREF=\"$PHP_SELF?aid=$aid&page=$prevpage\">".
    "Previous Page</A>&nbsp;&nbsp;");}


    if ($page < count($textarray) - 1) {
    $nextpage = $page + 1;
    echo("&nbsp;&nbsp;<A HREF=\"$PHP_SELF?aid=$aid&page=$nextpage\">".
    "Next Page</A>");}

    Al it does is display !!!TOKEN!!![pagebreak]title here[/pagebreak].

    Any help really appreciated
    <Edited by petesmc on 01-09-2001 at 03:25 PM>


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
  •