need help making images and text into clickable links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scmeeker
Forum Newbie
Posts: 9
Joined: Sun Jun 13, 2010 5:37 pm

need help making images and text into clickable links

Post by scmeeker »

I'm trying to make my text and images into clickable links. The images and text are in a database so its getting really tricky for me since I'm new to PHP. I've tried many different ways without success.

Here is a snippet of the code I'm working with. As you can see, I'm also working with an image re-sizer. I would really like to make those images and text
clickable links(i.e. Title). Any help is appreciated! :D

if ($res) {
while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) {
$detail = $newArray['id'];
$photo = $newArray['photo'];
$id = $newArray['title'];
$price = $newArray['price'];


list($width) = getimagesize($photo);
// set the maximum width of the image here
$maxWidth = 100;
if ($width > $maxWidth)


echo "<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$photo\" />";

echo "Title:".$id." Price:".$price."<br/";
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: need help making images and text into clickable links

Post by Jonah Bron »

Replace

Code: Select all

echo "<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$photo\" />"; 
With this

Code: Select all

echo '<p><a href="wherever/you/want/to/go"><img alt="Image" width="$maxWidth" src="$photo" /></a>'; 
scmeeker
Forum Newbie
Posts: 9
Joined: Sun Jun 13, 2010 5:37 pm

Re: need help making images and text into clickable links

Post by scmeeker »

Thanks Jonah.

I tried that code but with the single quotes ' ' surrounding it, it disabled the MySql connection in some way. It wouldn't display any of the images from the database but rather just the word "Image" as a link. I tried replacing the singles with the double quotes but that gave me a string error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'
scmeeker
Forum Newbie
Posts: 9
Joined: Sun Jun 13, 2010 5:37 pm

Re: need help making images and text into clickable links

Post by scmeeker »

This was the code that resolved my issue:

Code: Select all

echo "<p><a href=\"painting.php\"><img alt=\"Image\" width=\"{$maxWidth}\" src=\"{$photo}\" /></a>";
Thank you!
Post Reply