Jump to content

trying to make text and images into clickable links


scmeeker

Recommended Posts

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/";

Link to comment
Share on other sites

For some reason it keeps giving me this error when I try to use it:

  Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

 

Here is the changed code:

 

echo "<p><a href="painting.php"><img alt=\"Image\" width=\"$maxWidth\" src=\"$photo\" /></a>";

 

 

Link to comment
Share on other sites

For some reason it keeps giving me this error when I try to use it:

  Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

 

Here is the changed code:

 

echo "<p><a href="painting.php"><img alt=\"Image\" width=\"$maxWidth\" src=\"$photo\" /></a>";

 

I believe it should be

echo "<p><a href="painting.php"><img alt=\"$Image"\ width=\"$maxWidth"\ src=\"$photo"\ /></a>";

the second \ for each one was outside the ""'s and images was missing a $

Link to comment
Share on other sites

For some reason it keeps giving me this error when I try to use it:

  Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

 

Here is the changed code:

 

echo "<p><a href="painting.php"><img alt=\"Image\" width=\"$maxWidth\" src=\"$photo\" /></a>";

 

 

 

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

Link to comment
Share on other sites

Wow!  Thanks everyone!  It was isedeasy's post who resolved the problem.  It was the brackets {} that I needed.  This was the code that resolved my issue: 

 

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

 

Thank you!

Link to comment
Share on other sites

  • 1 year later...

You should probably switch these around to make more sense.

from:

$detail = $newArray['id'];
$photo = $newArray['photo'];
$id = $newArray['title'];
$price = $newArray['price'];

 

to:

$id = $newArray['id'];
$photo = $newArray['photo'];
$detail = $newArray['title'];
$price = $newArray['price'];

 

 

You should really do all the positioning with some sort of css styling to get it the exact way you want.

echo "<p><a href=\"$photo\"><img title=\"$detail\" alt=\"$detail\" width=\"$maxWidth\" src=\"$photo\" /></a><br />$detail";

 

Other ways you can do the same links.

 

If wrapped with double quotes, all single quotes within

echo "<p><a href='$photo'><img title='$detail' alt='$detail' width='$maxWidth' src='$photo' /></a><br />$detail";

 

or use concatenation

echo "<p><a href='".$photo."'><img title='".$detail."' alt='".$detail."' width='".$maxWidth."' src='".$photo."' /></a><br />".$detail;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.