I’m creating a photo tagging project using mysql and php, that not only just adds tags to photos but it also returns related tags that I have stored in the my database. I am almost done my project (sort of), just stuck on the part where i have to return the related tags when i upload the photos.
My database is called tagger and i have two tables “image”(ImageId, Name, TagId) and “tag”(ID, Tag).
I have 3 php pages database.php, index.php (where i upload the image with tag), and show.php i have no problem uploading the images with tags but i also want to make it in way that returns related tags as well. For example if i uploaded a baby picture and added the tag “baby smile” when i upload it, it would write next to “baby smile child laugh”. i don’t know how to do that.
This is my code for show.php:
<?
require_once('/database.php');
$dbconnect = NEW DB_Class('tagger', 'root', '');
$query = "SELECT * FROM image, tag WHERE image.TagID = tag.ID";
$result = $dbconnect->fetch($query);
echo "<table border='2'>";
foreach ($result as $record)
{
echo "<tr>";
echo "<td>";
echo "<a href='images/".$record['Name']."' target='_blank'>
<img src='images/".$record['Name']."' alt='SSsss' height='120' width='120' /></a>";
echo "</td>";
echo "<td>";
echo $record['Tag'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
<form name="newad" method="post" enctype="multipart/form-data"
action="">
<table align="center" >
<tr>
<td> <h2>Image to upload: </h2> </td>
<td><input type="file" name="image"></td>
</tr>
<tr>
<td><h2>Tags:</h2></td>
<td><input type="text" name="tags"/></td>
</tr>
<tr>
<td></td>
<td><input name="Submit" type="submit" value="Upload image" style="width 120px; height: 70px;font-size:20px"></td>
</form>
</tr>
<br/>
</table>
</form>
Would i have to add like a whole new table called “synonyms” for example? I’m totally lost, any help would be much appreciated. If you guys need to see the codes for the other two pages, I’ll show those as well. Thanks.
Your database schema looks like you can add only one tag for an image, but your using “tags” in your description. Lets asume this is your table schema Image: (ImageId, Name), and Tag(TagId, ImageId, Tag). Make the appropriate modifications if necessary.
Now create the synonyms table as a cached table, that can be updated from as a cron job.
And then insert rows into the cached tabled. If you don’t have a lot of images you can just call this query each time.
So if your table looks like this
Your result will be:
(tag, related_tag, connections)
This way you can create a table that shows which tags appear together in 5 images or more.