SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    generating image links on the fly

    ok, here it is.
    i want to display images from artists' directories, but i'd like to be able to do it on the fly (meaning i don't want to hand code every image link)

    i think i'm on the right track, but i can't figure out how to make the script recognize incremental names of the images.

    here's what i have so far :

    PHP Code:
    // create image links on the fly

    for ($i = 0 ; $i <$num_images; $i++) {

        $link .= "
        <a href="javascript:;" onClick="openProfileImage('img_url[]','200','342','$artist_name','450','200')"></a></td>
        ";
        
    }


    <? echo "$link"?>
    openProfileImage is a JS function to open a pop-up window with an image in it.
    i just want to be able to generate the correct number of links that corresponds to the number of images in a directory, most likely by supplying the script with a number as in $num_imgs=3.

    if i'm doing it correctly, the above code might (if i'm lucky) generate the correct number of images but of the same image.

    i'm totally lost regarding the next step so any help would be appreciated.

    thank you very very much in advance.
    . . . chris

  2. #2
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    here...

    PHP Code:
    //*create*image*links*on*the*fly



    for*($i*=*0*;*$i*< $num_images;*$i++)*{

    ****$link*.=*"<a*href="java script:;"*onClick="openProfileImage('img_url[$i]','200','342','$artist_name','450','200')"></a></td>

    ****";

    ****

    }


    <?*echo*"$link";*?>

    notice the "img_url[$i]" .


    if that is acutally an array, and the array has $num_images in it, that ought to work.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And it should be $img_url[$i] not img_url[$i]
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, thanks.

    i'm working on it right now and although i trust the code you guys gave me, i still can't wrap my head around it.

    if there are 3 images in the directory

    image1.jpg
    image2.jpg
    image3.jpg

    then img_url[$i] is going to generate 3 image links. i get that part.

    the part i'm having trouble understanding is how/wether the links will be to the 3 different images?
    i hope that makes sense..
    . . . chris

  5. #5
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one more question.

    can i use a relative path or would i need to use the absolute path for the image url?
    . . . chris

  6. #6
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, this is where i worked up to. it's little messy so bear with me.

    [php]
    $link .= "<td width=\"10\" height=\"10\"><a href=\"javascript:;\" onClick=\"openProfileImage('$img_url[$i]$myrow[img_name]$i$myrow[img_ext]','200','342','$myrow[fname] $myrow[lname]','450','200')\">
    </php]

    at this point everything works great except for where the $i is.

    so instead of being www.domain.com/images/image01.jpg it looks like www.domain.com/images/image.jpg

    any ideas?
    . . . chris

  7. #7
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    important question

    Is the list of images you'll be using stored in a MySQL database, or do you just want to use the ones stored in a folder?

    if they're in a folder, you'll have to get that folders contents as an array, and then just do this:

    PHP Code:

    foreach ($file_array AS $v) {
        
    links .= "<a href='whatever.html'><img src='$v></a>";


    other wise you'll use a while loop if it's from a MySQL results.
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  8. #8
    SitePoint Addict
    Join Date
    Dec 2000
    Location
    BOSTON MA
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you just lost me.

    the images are in a directory.

    /imgs/
    image1.jpg
    image2.jpg
    image3.jpg

    the way i'm doing it now is this. the link to the image basically is :
    Code:
    <a href=\"java script:;\" onClick=\"openProfileImage('$img_url[$i]$myrow[img_name]$i$myrow[img_ext]','200','342','$myrow[fname] $myrow[lname]','450','200')\">
    where $i is incrementing so that it basically looks like this :

    Code:
    <a href="java script:;" onClick="openProfileImage('/imgs/image$i.jpg','200','342','joe sparks','450','200')">
    . . . chris


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
  •