Jump to content

Recommended Posts

Hey everyone, I'm trying to select multiple rows from one table, depending on the ID given from another table.

 

I've got it half working with the code below, however it echo's out each blog multiple times depending on how many different tags are assigned to it, how would I go about so it displays multiple tag's on one copy of the blog post?


	$sqlCommand = "SELECT blogid, blogtitle, content, blogtime, category, blogseourl, author FROM blog ORDER BY blogtime DESC";
		$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
	$blogDisplay = '';
			while ($row = mysqli_fetch_array($query)) {
			$blogid = $row["blogid"];
			$blogtitle = $row["blogtitle"];
			$content = $row["content"];
			$blogtime = $row["blogtime"];
			$category = $row["category"];
			$blogseourl = $row["blogseourl"];
			$author = $row["author"];
			$contentshort =  substr($content, 0, 250);
		$sqlCommand2 = "SELECT tag FROM blogtags WHERE blogid='$blogid'";
		$query2 = mysqli_query($myConnection, $sqlCommand2) or die (mysqli_error());		
			while ($row = mysqli_fetch_array($query2)) {
			$tag = $row['tag'];
			
	$blogDisplay .= '<h1><a href="/blog/'. $blogseourl .'"> ' . $blogtitle . ' </a></h1> ' . $contentshort . '... <a href="/blog/'. $blogseourl .'">Read More...</a><br /><br /> ' . $author . ' posted on ' . $blogtime . ' |	 Category: ' . $category . ' |	 Tags: ' . $tag . ' | <a href="/blog/'. $blogseourl .'#disqus_thread"></a>'; 
			}
			}
	mysqli_free_result($query);	

So everything is working correctly apart from it echoing multiple $blogDisplay's for each tag.

 

Anyone got any ideas? 

Link to comment
https://forums.phpfreaks.com/topic/277044-phpmysql-multi-table-selections/
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.