SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: 2D arrays

  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)
    here is my code:

    if (!isset($page)) $page = 0;
    $textarray=explode("[PAGEBREAK]",$text);
    $text=$textarray[$page];
    $bits=explode("|",$text);
    echo "<font size='3' ><P>".$bits[1]."</p></font>";
    echo "<font size='2' ><P><b>".$bits[0]."</b></p></font>";
    echo( "<font size='2'><P>$bits[2]</p></font>" );

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

    ---------

    As you can see, i split pages and get titles and chapter names. $bits[0] is the title for the current page. As you can see lower, $nextpage is $page + 1.

    Now below that you can see:
    ... $nextpage\">$bits[0]</A>"); } ...

    Where is says $bits[0] i really need it to say next pages $bits[0]. How would i do this. I tried

    $bits[0][$nextpage] and $bits[0[$nextpage]] however both don't work.

    Does anyone know how to do this?

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use 2D array OR:

    if (!isset($page)) $page = 0;
    $textarray=explode("[PAGEBREAK]",$text);
    $text=$textarray[$page];
    $bits=explode("|",$text);
    echo "<font size='3' ><P>".$bits[1]."</p></font>";
    echo "<font size='2' ><P><b>".$bits[0]."</b></p></font>";
    echo( "<font size='2'><P>$bits[2]</p></font>" );

    if ($page < count($textarray) - 1) {
    $nextpage = $page + 1;


    $text=$textarray[$nextpage];
    $bits=explode("|",$text);


    echo("&nbsp;&nbsp;<A HREF=\"$PHP_SELF?aid=$aid&page=$nextpage\">$bits[0]</A>"); }
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  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)
    Thanx that worked, but just for the record, how would i do the 2D array because at the start of documents i might want to list the title for every page then i would have to create and array to do this.

    Also, how would you output this array?

  4. #4
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To use 2D array in PHP:

    $textarray=explode("[PAGEBREAK]",$text);
    for ($i=0;$i<count($textarray);$i++)
    { 2Darray[] = explode("|",$textarray[$i]);
    }

    to print it out:

    for ($i=0;$i<count($2Darray);$i++)
    { echo($2Darray[$i][0]);
    }

    How is that?
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  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)
    Thanx,

    Just wondering if you could help:

    using my code above, On a print template PHP script, how could i make php ignore the splitting pages but still insert all the titles and chapters in the right place?

  6. #6
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't quite understand what you're trying to do, probably more details are needed
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  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)
    Okay, the script that i have posted at the top Gets an article and splits the article over many pages, and getting the title and or chapter from within the article.

    IE

    $bits=explode("|",$text);
    echo "<font size='3' ><P>".$bits[1]."</p></font>";
    echo "<font size='2' ><P><b>".$bits[0]."</b></p></font>";
    echo( "<font size='2'><P>$bits[2]</p></font>" );


    Now what i want to do is, display the article, but not split the article over many pages. However i want to still be able to display the page title and chapter in the position intended.

    page
    ---------------------------------

    Part 1: introduction

    Basics

    fadfasdfasdf
    asdfasdfasdf
    asdfasdfasdf
    asdfasdfasd
    fasdfasdfas
    dfasdfasdfa

    Another title

    asdasdasda
    sdasdasd
    asdasdasdas
    dasddgasdfg
    afgasdfgafg

    Another title

    fasdfasdfasdf
    asdfasdfasd
    fasdfasdf
    asdfasd
    fasdf

    --------------------------


    Notice there is no page breaks


  8. #8
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You still need PAGEBREAK as it will define where will the next chapter be.


    $textarray=explode("[PAGEBREAK]",$text);
    for ($i=0;$i<count($textarray);$i++)
    {
    $text=$textarray[$i];
    $bits=explode("|",$text);
    echo "<font size='3' ><P>".$bits[1]."</p></font>";
    echo "<font size='2' ><P><b>".$bits[0]."</b></p></font>";
    echo( "<font size='2'><P>$bits[2]</p></font>" );
    }

    How is this?
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  9. #9
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That works perfectly. Script in action, i emphasized the titles:


    http://www.codingclick.com/print.php?aid=2

    LOL :-)

  10. #10
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That page might be too much for a newbie to digest!
    Glad I could help.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy


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
  •