/    Sign up×
Community /Pin to ProfileBookmark

Select word from string

Hi,

I want to show (photo)results which are similar as the current photo on a page. How can I do this?

I thought to select one or two words from the title of the current photo, put it in a database query and show the results on the page …

Or does anybody has other suggestions?

Thx! ?

Christophe

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@KruithneMay 03.2010 — If you have all the photos in a database table and going to be linking then via keywords from the titles I would do something like this ...

Have another column for each photo thats Keywords and put say 3 keywords for each.

[code=html]
<?php
//Current photos keywords (pull these from the current photos keywords field)
$keyword1 = 'Outdoors';
$keyword2 = 'Car';
$keyword3 = 'Person'; //Rubbish keywords ey :P

//Now we search for say 10 other photos with the same keywords..
$query = "SELECT * FROM Photos WHERE Keywords LIKE '&#37;$keyword1%' OR Keywords LIKE '%$keyword2' OR Keywords LIKE '%$keyword3' LIMIT 0, 10";
$result = mysql_query($query);
$count = 0;
echo "<table><tr>";
while($row = mysql_fetch_array($result)){
$count++;
if($count == 5){
echo "</tr><tr>";
}
$title = $row["Title"];
$thumb = $row["Thumbnail"];
$id = $row["PhotoID"];
echo "<td><a href="viewphoto.php?photo=$id"><img src="photos/thumbnails/$thumb"><br/>$title</a></td>";
}
echo "</tr></table>";
?>
[/code]


This is a very rough version and is untested and most likely won't run but it is just to give you an idea of what I would do. Hopefully it helps ?

Kruithne
Copy linkTweet thisAlerts:
@Christophe27authorMay 03.2010 — Thank you! I'll check it out ?
×

Success!

Help @Christophe27 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...