View Single Post
Old 10-08-2012, 02:57 PM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
INNER JOIN query help

Hi i have tried this a few ways and no results and no errors either. Im getting really tired so thought would ask for some help here.

The original query that works perfectly was

PHP Code:

$iscomment
=mysql_query("SELECT * FROM profile_comment WHERE com_memid =  $USERID AND com_approved = '1' ORDER BY com_time DESC",$link); 

So that will grab all the queried comments left by users and list those comments on the USERID profile (USERID is a copy of SESSIONID)

and that works fine but what i want to do is not list the comments from users who have hidden their profile.

So i need to do an INNER JOIN i think. I need to grab two other values from another table called adverts adv_paused and adv_approved


Here is my latest attempt and i will try to doc for you as we go.

This does not work by the way lol


PHP Code:

$iscomment
=mysql_query("SELECT *, 

// get all the fields needed from the profile_coments table
profile_comment.mem_id, profile_comment.com_memid, profile_comment.comment, profile_comment.com_approved, profile_comment.com_time, 

//also get the values from the adverts table for paused and approved
adverts.adv_paused, adverts.adv_approved 


FROM profile_comment

          INNER JOIN adverts ON(profile_comment.memid = adv_userid)  
        //grab advert for whoever left the comment 
        // memid is the person who left the comment, so grab the matching adv_userid from adverts table


       WHERE profile_comment.com_memid ='$USERID' AND com_approved = '1' 
         //now locate the profile for the signed on member in the table to pull their comments if any match their id.  USERID is a compy of SESSIONID so we want the locate those USERID records and make sure the comment has been approved. 

                                
                        ORDER BY profile_comment.com_time DESC"
,$link);
                        
//now order by com_time in desc order 
Seems simple but i cant get it to work lol

thanks in advance.
durangod is offline   Reply With Quote