SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all!

    I have written an array :

    $alpha = array(
    A=>'http://www.xplodercodes.com/codes/playstation/indexes/a.phtml',
    B=>'http://www.xplodercodes.com/codes/playstation/indexes/b.phtml',
    C=>'http://www.xplodercodes.com/codes/playstation/indexes/c.phtml',
    );


    i would like to ouput the information from the array as follows
    by using Keys and Values starting from $alpha[0]

    <a href='$val'>$key</a>

    Can anyone show me how to write the coding for it as what i have written only shows the last data, that is for C only.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while ( list($key$val) = each($alpha) ) {
       echo 
    "<a href='$val'>$key</a>";

    Last edited by freakysid; May 15, 2001 at 03:07.

  3. #3
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Showing them with PHPLib Template

    Thanks again, freaksid. U're da man!

    I would now like to pass the output to the template i made using phplib. Can i passed it to a variable only?

    Does anyone know how i can do that?

    I tried passing the result to a variable and then using

    $t->set_var

    but that only shows the last result only.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am not familiar with PHPLib, but I imagine you will want to format that output into a string rather than echoing it straight to the browser. Something like:

    $links = ''; // initialise links to be an empty string
    while*(*list($key,*$val)*=*each($alpha)*)*{
    **$links .=*"<a*href='$val'>$key</a>";
    }

    Now you can pass links in your call to $t->set_var
    eg

    $t->set_var('LINKS', $links);

    BTW, I read through your previous thread http://www.sitepointforums.com/showt...781#post161781 (to get the gist of what you wanted to do with PHPLib because I don't know it from experience) and I've just noticed that this is more or less what freddydoesphp gave you - with a minor adjustment to keep adding (concatenating) each link html to the string $links.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's take it a step further, since it appears you want to create alphabetical links in your script here is a simple way to do it using chr().

    PHP Code:
    $url_prefix 'http://www.xplodercodes.com/codes/playstation/indexes/';
    for(
    $i=65;$i<91;$i++) {
        
    $links .= sprintf('<a href="%s%s.phtml">%s</a>&nbsp;'$url_prefixstrtolower(chr($i)), chr($i));
        } 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool!

    well, another Thank you to you two!! I have made my first php/mysql/phplib script to work!


    freakysid: yea, i juts realised it was almost the same. damn
    anyway, thanks for making that clear

    Time to learn how to write better code and i guess, freddydoesphp, that is really a nice time for me to use it and get used to.


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
  •