Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » PHP




 Page 1 of 1 [ 5 posts ] 



Author Message
 Post subject: if x apperarsn othr table
 Post Posted: Thu Nov 12, 2009 11:09 am 
Offline

Joined: Sat Feb 21, 2009 2:25 pm
Posts: 51
I m havin a tab calld 'products' nd othr table calld 'flags'.

If somebody generally flags a pro it includes a row in 2 da flags tab
which wid the products unique 'id' value (as well as others).

I m havin a page in da admin panel which would show products that were
flagged, I m having a issue wid da query I need to use to achieve this.

Any help would be greatly appreciated.


Top 
 Post subject: Re: if x apperarsn othr table
 Post Posted: Thu Nov 12, 2009 11:10 am 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
could u show us da table structures?


Top 
 Post subject: Re: if x apperarsn othr table
 Post Posted: Thu Nov 12, 2009 11:10 am 
Offline

Joined: Sat Feb 21, 2009 2:25 pm
Posts: 51
yeah sure (sorry for posting in the wrong forum)

Code:
products
--id
--user
--status
--title
--image
--description
--link

flags
--id
--product
--reason
--description


Top 
 Post subject: Re: if x apperarsn othr table
 Post Posted: Thu Nov 12, 2009 11:11 am 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
this could be fetched using a simple inner join:

Code:
SELECT f.*, p.*
  FROM flags f
    INNER JOIN products p
    ON f.product=p.id
  ORDER BY f.id


here comes the pretty good explanation of joins in the wikipedia:

http://en.wikipedia.org/wiki/Join_(SQL)

as always, it was a good practise to trim the returned columns from a query to only the columns you intend to use, rather than the whole row.


Top 
 Post subject: Re: if x apperarsn othr table
 Post Posted: Thu Nov 12, 2009 11:11 am 
Offline

Joined: Sat Feb 21, 2009 2:27 pm
Posts: 59
Thanks that works a treat :)


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 5 posts ] 




Board index » Server Side Development » PHP


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron