Page 1 of 1

need help making images and text into clickable links

Posted: Sun Jun 13, 2010 5:47 pm
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/";

Re: need help making images and text into clickable links

Posted: Sun Jun 13, 2010 7:02 pm
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>'; 

Re: need help making images and text into clickable links

Posted: Sun Jun 13, 2010 8:29 pm
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 ';'

Re: need help making images and text into clickable links

Posted: Mon Jun 14, 2010 9:57 am
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!