chalrune Posted April 24, 2008 Share Posted April 24, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/102674-bookmarks-relating-to-tags-problem/ Share on other sites More sharing options...
chalrune Posted April 25, 2008 Author Share Posted April 25, 2008 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>";/>?> Quote Link to comment https://forums.phpfreaks.com/topic/102674-bookmarks-relating-to-tags-problem/#findComment-526870 Share on other sites More sharing options...
chalrune Posted April 26, 2008 Author Share Posted April 26, 2008 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>"; }?> Quote Link to comment https://forums.phpfreaks.com/topic/102674-bookmarks-relating-to-tags-problem/#findComment-527723 Share on other sites More sharing options...
chalrune Posted April 26, 2008 Author Share Posted April 26, 2008 can a mod please transfer this topic to MySQL Help? i never noticed i was in the wrong part of the forums :-\ Quote Link to comment https://forums.phpfreaks.com/topic/102674-bookmarks-relating-to-tags-problem/#findComment-527733 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.