SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks to Kevin's tutorial, I've had no problem splitting up my MySQL-stored documents sticking "[PAGEBREAK]" in the body of text.

    What I can't figure out, however, is how to have the links say something other than "Next Page", or "Previous Page" - I could've sworn that Kevin covered how to have your links read whatever you wanted them to...but I can't find it anywhere!

    Any advice?

  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)
    Where can I find Kevin's tutorial, I could show you how to put prev/next links on your page but it seems you are following some code that Kevin has written could you provide a link so I could check it out maybe I can help you then.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2000
    Location
    Canada
    Posts
    533
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the [PAGEBREAK] thing.. lol, i used that on geekarea.org's article system .. but with {: pagebreak:} (without the space).. except, i havent ever seen kevin's php tutorials. .hehe :P

    as for next / prev things... look at the number of pages, loop through it, create page=x variable passed in the link... in the query use things like LIMIT .. if your article is stored as separate rows, if not, just explode() based on pages and pull out..

    cant be that hard
    <Edited by Vinay on 01-01-2001 at 10:36 PM>
    cogito, ergo sum

  4. #4
    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'm an intermediate with PHP Vinay :P

    Freddy: it can be found here:
    http://www.webmasterbase.com/article.php?aid=228&pid=0

  5. #5
    SitePoint Member
    Join Date
    Aug 2000
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...

    Cheers,

    Fábio Dias

  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)
    Oh it looks as if the [PAGEBREAK] gets stored in the data in the database then you just look for that string within the fdata from the db, If you are looking at splitting resultsets into multiple pages you need something more along the linbes as what vinay described here is a simple working example:

    <?
    $db = mysql_connect("localhost", "", "");
    mysql_select_db("bestof");
    //Set this to the number per page
    $limit = 10;

    //This sets the offset to 0 if it isn't set
    if (!isset($offset)) $offset = 0;

    //Do a COUNT query to get the total records that we will be working with
    $countsql = "SELECT COUNT(*) as totalnum from listings WHERE something = '$something'";
    $countresult = mysql_query($countsql);
    $countrow = mysql_fetch_array($countresult);
    $totalnum = $countrow["totalnum"];

    //Do the real query
    $realsql = "SELECT * from listings WHERE something = '$something' LIMIT $offset, $limit";
    $result = mysql_query($realsql);
    while($row = mysql_fetch_array($result)) {
    print $row["Name"]."<br>";
    }

    //Create the new offset by adding the current offset to the limit
    $newoffset = $offset + $limit;

    //Check to see if the total number of records is greater than the limit if it is create the next link by creating a new offset which is the current plus the limit and make the link remembering to send the criteria data off to each page in this case $something
    if ($totalnum > $newoffset) {
    printf('<a href="%s?offset=%s&something=%s">next &gt;&gt;</a><br>', $PHP_SELF, $newoffset, $something);
    }

    Smae as above except for subtracting the offset to create the back button if the current offset is greater than the limit so it won't be on the first page
    if ($offset >= $limit) {
    $newoffset = $offset - $limit;
    printf('<a href="%s?offset=%s&something=%s">prev &lt;&lt;</a>', $PHP_SELF, $newoffset, $something);
    }
    ?>



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

  7. #7
    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've looked over the code a bit, and am quite confused: are you under the impression that I have each page as its own record in the database?

    All I do now is enter "[PAGEBREAK]" in the form field for the body of the document, and it splits it up that way...

  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)
    No I think in Kevin's case let's say there is a field called content that is huge and should be split between pages so when entering the data you put a [PAGEBREAK] wherever you want the page to be split now you read in the field from the database then you just split it on the [PAGEBREAK] This would split the data into an array with each page in a separate element. NOw you would just show the first element for the first page create a link to next that would display the second element of the array next time the page loads. My method is for splitting records say 10 per page
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    Non-Member
    Join Date
    Apr 2000
    Location
    Waco, Texas.
    Posts
    188
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not sure if this will help too much, but here goes nothing:

    Code:
    <?
    //Just pre-define a page id, to make the example easier to read
    $id = 2;
    
    $text = 'one day[PAGE]I ate[PAGE]food.[PAGE]it was[PAGE]good!';
    $pages = explode('[PAGE]',$text);
    
    echo $pages[--$id]."<br><br>";
    printf('<a href="%s?id=%s">Last Page</a> <a href="%s?id=%s">Next Page</a>',$PHP_SELF,$id,$PHP_SELF,2+$id);
    echo "<br>";
    
    //or print out links to all the pages
    $i = 0;
    $num = count($pages);
    while($i <= $num)
    {
           printf('<a href="%s?id=%s">%s</a>',$PHP_SELF,++$i,$i);
    }
    ?>
    which outputs "I ate", with "Last Page" linking to 1 and "Next Page" linking to 3.

    Hope that helps.
    <Edited by robp on 01-01-2001 at 11:40 PM>

  10. #10
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone willing to revive this and help me move forward a bit?

    Here's what I basically need. To use something like this within my $body field...

    [PAGEBREAK=Go on to Part 2!]

    ...and have it split it up into another page, with the link to the next page saying "Go on to Part 2!" - I've had no problem using explode() to split my documents into multiple pages using "[PAGEBREAK]" as a delimiter, but I'm not handy enough with regular expressions to create the appropriate title.

  11. #11
    imagine no limitations exbabylon's Avatar
    Join Date
    Dec 2000
    Location
    Idaho, USA
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's a shot at the full basic code:

    what the article looks like:

    Code:
    ID | Body | Date
    -----------------------------------------------------------------------
    1 | [PAGEBREAK]First Page[PAGEBREAK]Second Page[PAGEBREAK] | 2001-03-05
    -----------------------------------------------------------------------
    then your code "may" look like this? I'm not positive, but it might be a start....

    PHP Code:

    $sql 
    "SELECT * FROM table WHERE ID='$id'";
    $result mysql_query($sql);

    while(
    $row mysql_fetch_array($result)){
    $body $row['Body'];
    $id $row['ID'];

    $pages explode('[PAGEBREAK]',$body);

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

    echo(
    "$pages[$page]<br>");

    if(
    $page 0){
    $go_back $page 1;
    echo(
    "<a href=\"$PHP_SELF?id=$id&page=$go_to\">Previous</a>");
    }

    $page_num 0;

    while(
    $pages[$i] != ""){

    $page_name $page_num 1;
    echo(
    " <a href=\"$PHP_SELF?id=$id&page=$page_num\">$page_name</a>");

    $page_num++;
    }

    if(
    $page $page_num){
    $go_forward $page 1;
    echo(
    "<a href=\"$PHP_SELF?id=$id&page=$go_to\">Next</a>");
    }

    I'm not sure... I haven't had to ever use explode() before... this is also my first real try with some stuff.... hope this can be of some help!
    Last edited by exbabylon; Mar 5, 2001 at 20:06.
    Blamestorming: Sitting around in a group discussing why a deadline was missed or a project failed and who was responsible.

    Exbabylon- Professional Internet Services

  12. #12
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, that's the part I've already got a handle on - I need to be able to specify the title of the link, rather than just use "Next" and "Previous". Thanks anyway, though.


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
  •