Jump to content

get JOIN result more than one time from a table


speedy33417

Recommended Posts

I have a custom guest book with a table that stores the user_id of the person who started the thread and the user_id of the person who last added a post. How do I loop out the result of their name from the JOIN-ed table if I'm supposed to reference them the same way? Like $row['user_nick'] twice.

Im a little confused. Are you tying to pull that same information twice from within the same loop?

If so, you would run your query again in the loop, but, when you retrieve the results, instead of storing it in the variable row['user_nick'] like you did the first time, you would store it in row2['user_nick']. But, thats just a guess because I cant tell exaclty what you are trying to do.

Sorry. When I read my first post it didn't make much sense for either.  ;D

 

Here's the script

 

$sql = "SELECT gb_category.gb_cat_id, gb_category.gb_cat_last_post_date, gb_category.gb_cat_replies, gb_category.gb_cat_viewed, gb_category.gb_cat_subject, gb_category.gb_cat_last_post_user, users.user_nick
   FROM  gb_category INNER JOIN users ON gb_category.gb_cat_last_post_user = users.user_id
   ORDER BY gb_category.gb_cat_last_post_date DESC";
$results = mysql_query($sql);
$totalCat = mysql_num_rows($results);
while($row = mysql_fetch_assoc($results)) 
{
$catId[] = $row['gb_cat_id']; 
$catLastDate[] = $row['gb_cat_last_post_date']; 
$catReplies[] = $row['gb_cat_replies'];
$catViewed[] = $row['gb_cat_viewed'];
$catSubject[] = $row['gb_cat_subject'];
$userId[] = $row['gb_cat_last_post_user'];
$catLastUserNick[] = $row['user_nick'];
}

 

The problem is that I have another user_id in the gb_category table, which is called gb_cat_start_user.

gb_cat_start_user is the user id of the person who started the thread and gb_cat_last_post_user is the user id of the person who last posted on this thread.

I need both user ids and the user nick of those users. (right nowe the script is only getting the last post user stuff)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.