Jump to content

bookmarks relating to tags problem


chalrune

Recommended Posts

hello people i hope anyone have some time to help me with this question

 

ok i have three tables

 

[bOOKMARKS]

bookmark_id [PRIMARY KEY auto_increment]

bookmark_name

bookmark_url

 

[TAGS]

tag_id [PRIMARY KEY auto_increment]

tag_name

 

[bOOKMARKS_TAGS]

bookmark_id

tag_id

 

the table "bookmarks" are my bookmarks and the table "tags" are the used tags. i want to relate the bookmarks with the tags table using the connection table "bookmarks_tags"

 

$result2 = mysql_query("SELECT tags.tag_id, tags.tag_name FROM tags INNER JOIN bookmarks_tags ON bookmark_id = bookmarks_tags.bookmark_id INNER JOIN tags ON tag.id = bookmarks.tags.tag_id");
while ($row2 = mysql_fetch_array($result2)) {
echo "<a href=\"index.php?t={$row2['tag_id']}\">{$row2['tag_naam']}</a>";
}

 

i allready have this but it doesnt work. can anyone help me giving something like this

 

[a bookmark]

[all related tags]

 

i hope anyone can help me..

 

 

Link to comment
Share on other sites

i have solved my own problem and i am pretty happy about the result. it was the wrong use of the select statement. this is the piece of the code i used for future problem seekers.

 

<?php
	$result = mysql_query("SELECT b.bookmark_naam, b.bookmark_url, t.tag_id, t.tag_naam FROM bookmarks b LEFT JOIN bookmarks_tags bt ON bt.bookmark_id = b.bookmark_id INNER JOIN tags t ON t.tag_id = bt.tag_id");
	    $prevbookmark = "";
	    while($row = mysql_fetch_assoc($result)) {
	        if($row['bookmark_naam'] != $prevbookmark)
	        {
	            echo "<a href=\"{$row['bookmark_url']}\"><h1>{$row['bookmark_naam']}</a></h1>tags: ";
	            $prevbookmark = $row['bookmark_naam'];
	        }
			echo "<a href=\"index.php?t={$row['tag_id']}\">{$row['tag_naam']} | </a>";/>?>

Link to comment
Share on other sites

well it looks like it didnt work well after all... i still have a problem with the same select statement..

 

like when i have a bookmark with 2 tags on it, it will echo twice. when there is just one tag it will show just one.

 

i want this end result.

1 unique bookmark with all its tags. (like all bookmark_id get shown once)

 

<?php		$result = mysql_query("
	SELECT b.bookmark_naam, b.bookmark_url, t.tag_id, t.tag_naam
	FROM bookmarks b 
	LEFT JOIN bookmarks_tags bt ON bt.bookmark_id = b.bookmark_id 
	INNER JOIN tags t ON t.tag_id = bt.tag_id");
	$prevbookmark = "";
	while($row = mysql_fetch_assoc($result)) {
		if($row['bookmark_naam'] != $prevbookmark)
		{
			echo "<h2><a href=\"{$row['bookmark_url']}\">{$row['bookmark_naam']}</a></h2>tags: ";
			$prevbookmark = $row['bookmark_naam'];
		}
		echo "<span>";
		echo "<a href=\"index.php?t={$row['tag_id']}\">{$row['tag_naam']} </a>";
		echo "</span>";
	}?>

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.