Jump to content

inner join


tronicsmasta

Recommended Posts

Hey guys,

 

I need to join these tables :)

 

comments (table)
date
username
comment
channel

with: 

users (table)
username
avatar

 

There are more to these tables but what I have listed is only what I need...

 

What I want to do is get the username date comments from the comments table where channel = 01 and the avatar from the users table that matches the username...

 

 

Now the what I am trying to query is

SELECT comments.username, comments.date, comments.comment, users.avatar 
FROM comments, users WHERE users.username = comments.username AND comments.channel = 01 ORDER BY date DESC

 

Now mysql returns 0 rows. but when i run this:

SELECT comments.username, comments.date, comments.comment, users.avatar 
FROM comments, users WHERE users.username = comments.username ORDER BY date DESC

 

I get 2 entries from my comments table because there are 2 comments entries with that username but all I am trying to get from the users table is the avatar...

 

any ideas how i can do this?

 

I also tried:

 

while ($row = mysql_fetch_array($result)) {

	$username = stripslashes($row['username']);
	$comment = stripslashes($row['comment']);
	$date = $row['date'];

	$sqlA = "SELECT avatar FROM users WHERE username = '$username'";
	$resultA = @mysql_query($sqlA,$connection);
	$rowA = mysql_fetch_array($resultA);

	$avatar = $rowA['avatar'];


	echo "<ul>";
	echo "<li>";
	echo "$username - <span id=\"comment_date\">$date</span><br/><br/>";
	echo "<table>
			<td>
				<tr width=\"100\"><img src=\"$avatar\" width=\"100\" height=\"100\"></tr>
				<tr width=\"430\">    $comment - avatar: $avatar</tr>
			</td>
		  </table>";
	echo "</li>";
	echo "</ul>";
			} //end list all comments

 

but the avatar shows up with an X and avatar: is blank... but when i run $sqlA by itself... no problems I get that avatar...

 

hope this is clear...

 

thank you!

 

 

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.