-2

i have a php file that shows some pictures from a db..i want to make each picture as a link to a different page like: pic 1-link 1, pic 2-link 2 etc How i do that? Do i need to change something in this code maybe?

 echo "<td width=100>";
  echo "<div class='pulse'><img src='pictures/".$row['picture']."'></div>";
  echo "</td>";
Sef
  • 17
  • 2
  • Ummmm, yes, you'd need to add an `a` tag. Is the link stored in the same row as the picture? – jeroen Oct 08 '14 at 18:15
  • i have no inserted link right now, i want to make the pic like a link – Sef Oct 08 '14 at 18:24
  • You will have to explain more, how does a picture *like* a link? – jeroen Oct 08 '14 at 18:25
  • Your image and link columns should match. Using an `href` and pointing it to the related link would probaly require a `WHERE` clause in your query. Or something like `` - My quotes may be off, but that's the gist of it. – Funk Forty Niner Oct 08 '14 at 18:28
  • i mean when i click in the picture, to go in another link like facebook or youtube or whatever – Sef Oct 08 '14 at 18:30
  • Do you have rows with existing links related to the pictures? We need to know what your DB schema is. If you don't have one, then this question stands at getting closed of either being too broad and/or unclear. – Funk Forty Niner Oct 08 '14 at 18:36
  • i have a database, there are pictures of different products in it, and these are showed in my web page, so i needed when i click in a picture, to go in another page with more informations about the product! this is how it looks like: http://i.imgur.com/BeOaX2Q.jpg – Sef Oct 08 '14 at 18:40

2 Answers2

0

This will work for opening the image in a new browser window

echo "<td width=100>";
echo "<div class='pulse'><a target='_blank' href='pictures/".$row['picture']."'>".$row['picture']."</a></div>";
echo "</td>";
dkkumargoyal
  • 556
  • 3
  • 10
  • 2
    `target="_new"` - that should be `target="_blank"` - Here http://stackoverflow.com/q/4964130/ - *"Summary of current anwsers: `_new` doesn't have any special meaning. You could write `_white_little_lamb` as well."* - http://www.w3.org/TR/html401/types.html#type-frame-target – Funk Forty Niner Oct 08 '14 at 18:21
  • @Sef was the code you mentioned in the question is working properly to display all the images? My code just display the image name and on click will open the image assuming the image path pictures/".$row['picture'] is correct – dkkumargoyal Oct 08 '14 at 19:14
  • the pics are stored in a xampp db – Sef Oct 08 '14 at 19:20
0

It sounds like maybe you need this:

  echo '<td width=100>'
  echo '<div class="pulse"><a href="link'.$row['picture'].'"><img src="pictures/' . $row['picture'] . '"></a></div>';
  echo '</td>';

Notice that I changed your double quotes to singles. That was not entirely necessary, but it makes the concatenation easier for me to follow.

TecBrat
  • 3,643
  • 3
  • 28
  • 45
  • i just copy paste your code, but this shows nothing on my page right now :/ – Sef Oct 08 '14 at 18:33
  • I had introduced errors changing from double to single quotes. I _think_ i fixed it now. Check it carefully. – TecBrat Oct 09 '14 at 00:43