Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating links from a string 1

Status
Not open for further replies.

xxalex

Programmer
Feb 9, 2005
11
GB
Hello.
I am putting together a php photo gallery and have a field in the mysql database called photoKeywords. This contains some comma delimited keywords for each photo. eg. Cityname, Countryname, Peoplename

I have created a search page that displays all the photos, captions and keywords that match the search criteria. This works great but I would like to be able to click on a keyword shown beside a photo and rerun the search, finding all the other photos with that keyword.

To do this I need to change "Cityname, Countryname, Peoplename" into
<a href="viewerTags.php?tag=%25Cityname%25">Cityname</a><a href="viewerTags.php?tag=%25Countryname%25">Countryname</a><a href="viewerTags.php?tag=%25Peoplename%25">Peoplename</a>

I currently use the following code to display the thumbnails.

<?php
$counter = 0;
if ($totalRows_thumbs > 0)
{while($row_thumbs = mysql_fetch_assoc($thumbs)){
$counter = $counter + 1;
$thumbs1.= '<div class="comment">';
$thumbs1.= '</div>';
$thumbs1.= '<div class="commentmain">';
$thumbs1.= '<div class="photoinfo">';
$thumbs1.= 'Photo ID: ' . $row_thumbs['photoID'] . '<br />';
$thumbs1.= 'Caption: ' . $row_thumbs['photoCaption'] . '<br />';
$thumbs1.= 'Keywords: ' . $row_thumbs['photoKeywords'] . '<br />';
$thumbs1.= 'EXIF Info: Hover mouse over image <br />';
$thumbs1.= 'Gallery Name: ' . $row_thumbs['photoGallery'] . '<br /><br />';
$thumbs1.= '<a href="viewerDynamic.php?id=' . $row_thumbs['photoID'] . '&amp;gallery=' . $row_thumbs['photoGallery'] . '">View large image in original gallery</a>';
$thumbs1.= '</div>';
$thumbs1.= '<a href="viewerDynamic.php?id=' . $row_thumbs['photoID'] . '&amp;gallery=' . $row_thumbs['photoGallery'] . '"> <img class="image" src="thumbs/' . $row_thumbs['photoID'] . '" alt="' . $row_thumbs['photoExif'] . '" title="' . $row_thumbs['photoExif'] .'"></img></a>';
$thumbs1.= '</div>';

};
}else{
$thumbs1.= '<br >There are no photos that meet your criteria.<br />';
$thumbs1.= 'Please <a href="index.php">try again</a><br /><br >';
}
?>
<?php echo $thumbs1; ?>


Can I perform that change I mention above in this line:
$thumbs1.= 'Keywords: ' . $row_thumbs['photoKeywords'] . '<br />';
or should I give up now!

Thanks for taking the time to read this.
Alex
 
Alex, how about:

Code:
// create an array from your keywords
$keyword = split(",",$row_thumbs['photoKeywords'] );
thumbs1.= 'Keywords: ';

// list tag links for each keyword
foreach ($keyword as $word) {
  thumbs1.= "<a href=\"viewerTags.php?tag=%25{$word}%25\">$word</a> ";
thumbs1.= '<br />';
}

--RHYNO
 
Thanks rhyno!
That has worked a treat.
If you wanna have a look at the gallery you can see it at
2 mysql tables, 3 php pages - hopfully hundreds of holiday photos!

Cheers for your help.
Alex
 
Alex,


Nice site. Seems to work well and looks like a great start. You may want to take a look at your <div>s ("photoinfo") - they're getting blown out a bit in Firefox...

Glad to be of help. The people here usually are to me, so you just gotta try to pay it forward.
 
Cheers for the comments. I noticed the photoinfo div problem when I installed firefox there; should be easy enough to fix. It's not happening in Safari or Opera.
I fear testing it in internet explorer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top