this is very tricky. i´ve got a table with 2 columns thread_tag_map: thread_id and tag_name.
thread_id tag_name
1 football
1 manchester
2 manchester
2 england
3 england
3 queen
4 queen
4 diana
as you can see one thread can have multiple tags, and this give us a linking effect of tags.
if you type the tag football i want it to show all related tags to football. that is to say manchester, england, queen and diana.
so here is what ive coded so far:
// get all thread_id:s for tag_name
$query = "SELECT *
FROM thread_tag_map
WHERE tag_name = 'football'";
$result1 = mysqli_query($conn, $query) or die ("Couldn't execute query: " . mysqli_error($conn));
// get all tag_name:s for each thread_id
while($row = mysqli_fetch_assoc($result1))
{
$thread_id = $row['thread_id'];
$query = "SELECT *
FROM thread_tag_map
WHERE thread_id = $thread_id";
$result2 = mysqli_query($conn, $query) or die ("Couldn't execute query: " . mysqli_error($conn));
// add each tag to array
while($row = mysqli_fetch_assoc($result2))
{
$tag_array[] = $row['tag_name'];
}
}
but this just give me football and manchester. i dont know how i can proceed to make it a good code to loop (for loop?) it through. maybe there is 100 related tags.
i think you understand the idea. has someone done this before?