SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    breaking info from database into multiple pages

    So I'm pulling information from a database. One of the fields, the interview field is rather long on some entries, so I want to break it down into multiple pages. It was suggested to me that I enter in [pagebreak] in the database field where I want the article to break at, so that I can ensure that it doesn't break mid sentence. This code is broken into 3 parts as I'm showing below. It's not currently working, it's breaking on this line:

    function page_url(page) {

    with the error: Parse error: syntax error, unexpected T_STRING, expecting ')'

    In addition to that can you guys let me know if this set up looks good? Thanks!



    PHP Code:
    <?php
    $page_break 
    "[pagebreak]";

    // Default is page 1
    $page 1;

    // Set the page we're currently on
    if(isset($_GET["page"])) {
            
    $page $_GET["page"];
    }

    // Get our article body out of the database
    $article_body "This is page 1 of my article. [pagebreak] This is where page 2 of my article is.";

    // Split our article into pages
    $article_pages str_split($article_body$page_break);
    ?>

    PHP Code:
    <?php 
            
    // Display our page
            
    print($article_pages[$page 1]); 
    ?>

    <?php
            
    function page_url(page) {
                    return 
    "tvinterview.php?id=".$_GET["id"]."&page=".page;
            }

            
    $previous_link "";
            
    $next_link "";
            
            if(
    $page 1) {
                    
    previous_page $page 1;
                    
    $previous_link page_url(previous_page);
            }
            
            if(
    $page count($article_pages)) {
                    
    next_page $page 1;
                    
    $next_link page_url(next_page);
            }
    ?>

    PHP Code:
    <ul class="page-navigation">
    <!-- Previous Link -->
    <?php if($previous_link == "") { ?>
            <li>Previous</li>
    <?php } else { ?>
            <li><a href="<?php print($previous_link); ?>">Previous</a></li>
    <?php ?>

    <!-- Numbered Links -->
    <?php foreach($article_pages as $index => $page_body) { ?>
            <?php if($page == $index 1?>
                    <li><?php print($index 1?></li>
            <?php } else { ?>
                    <li><a href="<?php print(page_url($index 1)); ?>"><?php print($index 1); ?></a></li>
            <?php ?>
    <?php 
    ?>

    <!-- Next Link -->
    <?php if($next_link == "") { ?>
            <li>Next</li>
    <?php } else { ?>
            <li><a href="<?php print($next_link); ?>">Next</a></li>
    <?php ?>
    </ul>

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The function str_split() splits the string by character and second your second argument is wrong. and in your case str_split() function is not the suitable function though. Just replace your str_split() to only split() or preg_split() then your code must work though I am not sure about your whole code since i have not tested it yet.
    Last edited by Raju Gautam; Jun 19, 2007 at 21:55. Reason: Also see the differences between those functions in your PHP manual.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I switched out str_split() to split() and I'm still getting the same error. Any other thoughts?

    I'm still a bit of a novice, I appreciate any help you can offer!

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change this line:
    PHP Code:
    $article_pages str_split($article_body$page_break); 
    To
    PHP Code:
    $article_pages split($page_break,$article_body); 
    Since the split() function gets the arguments as first pattern and second string and splits the string with the matched pattern and stores the values into the array. and here is $article_pages is your array.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I edited the line, still getting the:

    Parse error: syntax error, unexpected T_STRING, expecting ')'

    It's still in the same place.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Emma,

    Basically you are missing some $ signs off variables
    PHP Code:

    <?php 
            
    // Display our page 
            
    print($article_pages[$page 1]); 
    ?> 

    <?php 
            
    function page_url($page) { 
                    return 
    "tvinterview.php?id=".$_GET["id"]."&page=".$page
            } 

            
    $previous_link ""
            
    $next_link ""
             
            if(
    $page 1) { 
                    
    $previous_page $page 1
                    
    $previous_link page_url($previous_page); 
            } 
             
            if(
    $page count($article_pages)) { 
                    
    $next_page $page 1
                    
    $next_link page_url($next_page); 
            } 
    ?>
    Try that
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #7
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That moves my error to here:

    <?php } else { ?>

    at the end, and gives me this:

    Parse error: syntax error, unexpected T_ELSE

    Thanks again for your assistance, I really appreciate it

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    try
    PHP Code:
    <ul class="page-navigation"> 
    <!-- Previous Link --> 
    <?php if($previous_link == "") { ?> 
            <li>Previous</li> 
    <?php } else { ?> 
            <li><a href="<?php print($previous_link); ?>">Previous</a></li> 
    <?php ?> 

    <!-- Numbered Links --> 
    <?php foreach($article_pages as $index => $page_body) { ?> 
            <?php if($page == $index 1); ?> 
                    <li><?php print($index 1); ?></li> 
            <?php } else { ?> 
                    <li><a href="<?php print(page_url($index 1)); ?>"><?php print($index 1); ?></a></li> 
            <?php ?> 
    <?php ?> 

    <!-- Next Link --> 
    <?php if($next_link == "") { ?> 
            <li>Next</li> 
    <?php } else { ?> 
            <li><a href="<?php print($next_link); ?>">Next</a></li> 
    <?php ?> 
    </ul>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still getting the same error in the same place

  10. #10
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try ECHOing the RETURNed value...

    sometimes, what looks valid to our eyes, comes up bad to the compiler/interpreter... lol...
    leo d.

  11. #11
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What value should I echo? None of the page is currently show so should I just take out the code and echo certain values? If so which ones?

    thanks

  12. #12
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Can you paste the full error code as well Emma and the script in full?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  13. #13
    SitePoint Evangelist ldivinag's Avatar
    Join Date
    Jan 2005
    Location
    N37 33* W122 3*
    Posts
    414
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Emma View Post
    What value should I echo? None of the page is currently show so should I just take out the code and echo certain values? If so which ones?

    thanks

    oops... i missed the part that the error goes in another place.

    can i recommend something "smart" someone told here once...

    avoid jumping and in and out of php mode.

    either have all html or all php.

    you could easily just ECHOed (for example):

    Code:
    echo ("<li>Next</li>");
    granted in the grand scheme of life, the time lost or wasted as you jump in and out of php mode is VERY small, to me, it makes reading code a lot easier.
    leo d.

  14. #14
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still a novice, but I shall take the jumping in and out code to heart. I didn't know that it was something that was recommended!

    Current full code:

    PHP Code:
    <?php
    $page_break 
    "[pagebreak]";

    // Default is page 1
    $page 1;

    // Set the page we're currently on
    if(isset($_GET["page"])) {
            
    $page $_GET["page"];
    }

    // Get our article body out of the database
    $article_body "This is page 1 of my article. [pagebreak] This is where page 2 of my article is.";

    // Split our article into pages
    $article_pages split($page_break,$article_body); 


            
    // Display our page 

            
    print($article_pages[$page 1]); 


            function 
    page_url($page) { 

                    return 
    "tvinterview.php?id=".$_GET["id"]."&page=".$page

            } 



            
    $previous_link ""

            
    $next_link ""

             

            if(
    $page 1) { 

                    
    $previous_page $page 1

                    
    $previous_link page_url($previous_page); 

            } 

             

            if(
    $page count($article_pages)) { 

                    
    $next_page $page 1

                    
    $next_link page_url($next_page); 

            } 

    ?>




    <ul class="page-navigation"> 

    <!-- Previous Link --> 

    <?php if($previous_link == "") { ?> 

            <li>Previous</li> 

    <?php } else { ?> 

            <li><a href="<?php print($previous_link); ?>">Previous</a></li> 

    <?php ?> 



    <!-- Numbered Links --> 

    <?php foreach($article_pages as $index => $page_body) { ?> 

            <?php if($page == $index 1); ?> 

                    <li><?php print($index 1); ?></li> 

            <?php } else { ?> 

                    <li><a href="<?php print(page_url($index 1)); ?>"><?php print($index 1); ?></a></li> 

            <?php ?> 

    <?php ?> 



    <!-- Next Link --> 

    <?php if($next_link == "") { ?> 

            <li>Next</li> 

    <?php } else { ?> 

            <li><a href="<?php print($next_link); ?>">Next</a></li> 

    <?php ?> 

    </ul>

    error:

    Parse error: syntax error, unexpected T_ELSE


    and that is this line

    <?php } else { ?>

  15. #15
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try out this:
    PHP Code:
    <ul class="page-navigation"> 
    <!-- Previous Link --> 
    <?php if($previous_link == "") { ?> 
            <li>Previous</li> 
    <?php } else { ?> 
            <li><a href="<?php print($previous_link); ?>">Previous</a></li> 
    <?php ?> 
    <!-- Numbered Links --> 
    <?php foreach($article_pages as $index => $page_body) { ?> 
           <?php if($page == $index 1){ ?> 
                    <li><?php print($index 1); ?></li> 
            <?php } else { ?> 
                    <li><a href="<?php print(page_url($index 1)); ?>"><?php print($index 1); ?></a></li> 
            <?php ?> 
    <?php ?> 
    <!-- Next Link --> 
    <?php if($next_link == "") { ?> 
            <li>Next</li> 
    <?php } else { ?> 
            <li><a href="<?php print($next_link); ?>">Next</a></li> 
    <?php ?> 
    </ul>
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  16. #16
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you

    My page is showing up now with no errors, but it's still not working right. it's showing the text [pagebreak] inline with the rest of the content where it's supposed to break it into a new page, then at the bottom of everything I have this:

    # Previous
    # 1
    # 2
    # 3
    # 4
    # 5
    # 6
    # 7
    # 8
    # 9
    # 10
    # 11
    # 12
    # 13
    # 14
    # 15
    # 16
    # 17
    # 18
    # 19
    # 20
    # 21
    # 22
    # 23
    # 24
    # 25
    # 26
    # 27
    # Next

    They're all links that lead back to the first page. Here's the current code:

    PHP Code:
    <?php
    $page_break 
    "[pagebreak]";

    // Default is page 1
    $page 1;

    // Set the page we're currently on
    if(isset($_GET["page"])) {
            
    $page $_GET["page"];
    }

    // Get our article body out of the database
    $article_body "This is page 1 of my article. [pagebreak] This is where page 2 of my article is.";

    // Split our article into pages
    $article_pages split($page_break,$article_body); 

    ?>





    <?php 

            
    // Display our page 

            
    print($article_pages[$page 1]); 

    ?> 



    <?php 

            
    function page_url($page) { 

                    return 
    "tvinterview.php?id=".$_GET["id"]."&page=".$page

            } 



            
    $previous_link ""

            
    $next_link ""

             

            if(
    $page 1) { 

                    
    $previous_page $page 1

                    
    $previous_link page_url($previous_page); 

            } 

             

            if(
    $page count($article_pages)) { 

                    
    $next_page $page 1

                    
    $next_link page_url($next_page); 

            } 

    ?>





    <ul class="page-navigation"> 

    <!-- Previous Link --> 

    <?php if($previous_link == "") { ?> 

            <li>Previous</li> 

    <?php } else { ?> 

            <li><a href="<?php print($previous_link); ?>">Previous</a></li> 

    <?php ?> 

    <!-- Numbered Links --> 

    <?php foreach($article_pages as $index => $page_body) { ?> 

           <?php if($page == $index 1){ ?> 

                    <li><?php print($index 1); ?></li> 

            <?php } else { ?> 

                    <li><a href="<?php print(page_url($index 1)); ?>"><?php print($index 1); ?></a></li> 

            <?php ?> 

    <?php ?> 

    <!-- Next Link --> 

    <?php if($next_link == "") { ?> 

            <li>Next</li> 

    <?php } else { ?> 

            <li><a href="<?php print($next_link); ?>">Next</a></li> 

    <?php ?> 

    </ul>

  17. #17
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello i wrote the code for you and well tested too if your requirement is like this:
    PHP Code:
        $data "Curabitur bibendum porta sem. Fusce rutrum quam vel ipsum. Donec sem. 
                [PAGE_BREAK]Nulla condimentum justo et ligula. Nam ut ipsum. Aliquam mauris. Nulla malesuada metus egestas ipsum. 
                [PAGE_BREAK]Nam nonummy sem a lacus. In condimentum pharetra est. Duis lacus. Maecenas at tortor et elit ornare sollicitudin."
    ;
        
        
    $delim "[PAGE_BREAK]";
        
        if(isset(
    $_GET['page'])){
            
    $page $_GET['page'] - 1;
        }else{
            
    $page 0;
        }
        
        
    $pages split("\[PAGE_BREAK\]"$data);
        echo 
    '<div style="border:1px #000000 inset;width:400px;height:150px;overflow:auto;background-color:#FFFFFF;padding:2px;">';
        if(
    count($pages) >= 1){
            echo 
    $pages[$page];
        }
        else{
            echo 
    $data;
        }
        echo 
    '</div>';
        echo 
    '<div style="border:1px #000000 inset;width:400px;overflow:auto;background-color:#FFFFFF;padding:2px;">';
        echo 
    "| ";
        for(
    $i 1$i <= count($pages); $i++){
            if(
    $i == $_GET['page']){
                echo 
    "$i | ";
            }else{
                echo 
    "<a href=\"./paging.php?page=$i\">$i</a> | ";
            }
        }
        echo 
    '</div>'
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  18. #18
    SitePoint Zealot Emma's Avatar
    Join Date
    Sep 2004
    Location
    atlanta
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, thank you rajug! I modified it a bit for my needs and it works beautifully.

    Your help is much appreciated!


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
  •