SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying my image link in its own tempalte and not in browser

    Hi all of you good peeps,
    As it is now my code displays the image in the browser. I would like to display my image in a template. Where should I point my "href" attribute?? See my code below
    -----------------------------
    <?php if(count($files) > 0) : ?>
    <?php foreach($files as $f) : ?>
    <div>
    <a href="?action=view&amp;id=<?php htmlout($f['id']);?>">// I wish to display the image in a template here
    <img src="?action=view&amp;id=<?php htmlout($f['id']);?>" border="0" width="90"/>
    </a>
    </div>
    <?php endforeach; ?>
    <?php endif;?>
    -----------------------------

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    No idea what you mean by a template.

  3. #3
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    No idea what you mean by a template.
    I mean in it's own html(a template is a file that contains both html and php)

  4. #4
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I mean in its own html file. A template is a file that contains both html and php code. As it is now the image is only displayed in the browser and I'm unable to add any text attached to the image.

  5. #5
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    If you have a page say display.php and the link to this page would be <a href=display.php?photo=1.jpg"> you could get the photo name from the URL using $_GET['photo']; and then display the photo on the page. Is this the sort of thing you want to do? But where will the text come from?

  6. #6
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chief,
    Yes, this is exactly the thing I want to happen. I will be fetching the text from a text field in my text table or I could add the text myself manually - the important thing for me right now is that the functionality works. I'm in a harry to a meeting and will try your "hack" sometime today and let you know. Here is my code that didn't work

    --------
    <?php if(count($files) > 0) : ?>
    <?php foreach($files as $f) : ?>
    <div>
    <a href="?action=view&amp;id=<?php htmlout($f['id']);?>">// I wish to display image in a template here
    <img src="?action=view&amp;id=<?php htmlout($f['id']);?>" border="0" width="90"/>
    </a>
    </div>
    <?php endforeach; ?>
    <?php endif;?>

  7. #7
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,410
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    This is what I would do:

    On the main page you are linking from
    PHP Code:
    <a href="display.php?ref=1">Link</a
    A page called display.php
    PHP Code:
    <?php
    /*** Connect to the database ***/
    include 'connect.php';

    $referance $_GET['ref'];

    // Select the photo details from the database
    $result mysql_query("
    SELECT * FROM photos 
    WHERE ( ID = '
    $referance' )"
    or exit ( mysql_error() ); 
     
    $row mysql_fetch_array$result );

    $photo $row["photo"];

    $size getimagesize($photo);

    echo 
    "<img src=\"$photo\" ".$size[3]."\">";

    echo 
    "<p>".$row["photo"]."</p>";
    ?>


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
  •