www.webdeveloper.com
Results 1 to 5 of 5

Thread: Link to same page different image

Hybrid View

  1. #1
    Join Date
    Jan 2008
    Posts
    42

    Link to same page different image

    Hi,

    I have over 100 images I would like to display on their own page, but link to them from an index page.

    Rather than have over 100 seperate pages can anyone think of a way to link to the same page but call the required image. This is an over simplification of what i'd like to do:
    <a href = 'index.html' = 1.jpg></a> - Will open index.html and show 1.jpg.
    <a href = 'index.html' = 2.jpg></a> - Will open index.html and show 2.jpg.

    Is this possible?

    Many thanks in advance.

    Martin

  2. #2
    Join Date
    Oct 2007
    Posts
    175
    ..I would use php, not javascript.
    "The one who's closer to the truth is the one still looking"
    Jodarecode "Hence" - Chaos -

  3. #3
    Join Date
    Jan 2008
    Posts
    42
    Hi Jodarecode,

    Do you have a solution or are you suggesting I post this query in the PHP forum instead?

  4. #4
    Join Date
    Oct 2007
    Posts
    175
    This was a quick one I came up with, it works in firefox so far.
    I hope this helps!!

    test1.php
    PHP Code:
    <?php

    $img1 
    "image1.jpg";
    $img2 "image2.jpg";
    $img3 "image3.jpg";

    $i 1;

    ?>

    <html>
    <body>

    <form action="test2.php" method="post" name="myform<?=$i++?>">
    <input type="hidden" value="<?=$img1?>" name="img" id="img">
    <a href="#" onclick="document.forms['myform1'].submit()"><img src="<?=$img1?>"></a>
    </form>

    <form action="test2.php" method="post" name="myform<?=$i++?>">
    <input type="hidden" value="<?=$img2?>" name="img" id="img">
    <a href="#" onclick="document.forms['myform2'].submit()"><img src="<?=$img2?>"></a>
    </form>

    <form action="test2.php" method="post" name="myform<?=$i++?>">
    <input type="hidden" value="<?=$img3?>" name="img" id="img">
    <a href="#" onclick="document.forms['myform3'].submit()"><img src="<?=$img3?>"></a>
    </form>

    </body>

    </html>
    test2.php
    PHP Code:
    <?php

    $img 
    $_POST['img'];

    ?>

    <html>
    <body>
    <center>
    <img src="<?=$img?>">
    </center>
    </body>
    </html>

    Edit: if its not working try changing <?=$img?> to <?php echo $img?>
    Last edited by Jodarecode; 07-16-2010 at 02:39 PM.
    "The one who's closer to the truth is the one still looking"
    Jodarecode "Hence" - Chaos -

  5. #5
    Join Date
    Aug 2007
    Posts
    3,767
    If you need a direct link, you can modify Jodarecode's example to provide one (presuming the images are numbers).
    index.html
    Code:
    <!-- HTML -->
    <?php if (ctype_digit($_GET['img'])) {
    echo '<img src="'.$_GET['img'].'">';
    <!-- HTML -->
    index.html?img=1
    Great wit and madness are near allied, and fine a line their bounds divide.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles