Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,256
Total Threads: 106,575
Total Posts: 592,698
There are 89 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

JOIN two queries using the 1st query results?

Thread title: JOIN two queries using the 1st query results?
Reply  
Page 2 of 2 < 1 2
    Thread tools Search this thread Display Modes  
09-21-2012, 11:24 PM
#11
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Nailed the code into a single query.

PHP Code:
SELECT `ft`.`slug`, `ft`.`titleFROM `forum topics` AS `ftWHERE `ft`.`themeIN(SELECT `t`.`idFROM `users themes` AS `utLEFT JOIN `themes` AS `tON `ut`.`themeid` = `t`.`idWHERE `ut`.`userid` = '{$user->id}'ORDER BY `ft`.`dateASC 

Reply With Quote
09-22-2012, 12:12 AM
#12
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Okay. Another JOIN question. This time I'm trying to add two left JOINS to the same query.

Any reason why this isn't working?

PHP Code:
SELECT topics.id idtopics.themetopics.titletopics.revisedtopics.lockedtopics.dateusers.usernameusers.imageusers.rolethemes.id themeidthemes.name

FROM 
`forum topicstopics LEFT JOIN users ON users.id topics.author

LEFT JOIN themes ON themes
.id topics.theme

WHERE slug 
'{$slug}' ORDER BY topics.id LIMIT 1 
If I remove the second LEFT JOIN line and ", themes.id themeid, themes.name" the query works fine.

Reply With Quote
09-22-2012, 12:35 AM
#13
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

That looks like it should work, what error are you getting?

Reply With Quote
09-22-2012, 02:24 AM
#14
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

Ugh. Feel so stupid.

I had a column in my themes table called slug which was clashing with my topic slug. Simply rewriting that part as topics.slug did the trick.

Reply With Quote
09-22-2012, 03:20 PM
#15
mikeroq is offline mikeroq
mikeroq's Avatar
Status: Member
Join date: Feb 2006
Location: Ponca City, OK
Expertise: xHTML/CSS/PHP/Computer Tech
Software: Photoshop, Notepad++, Winamp
 
Posts: 332
iTrader: 5 / 100%
 

mikeroq is an unknown quantity at this point

Send a message via AIM to mikeroq Send a message via MSN to mikeroq Send a message via Yahoo to mikeroq

  Old

Have you thought about using a timestamp as your date/time? (I know its off topic, but I was reading your array!)

Reply With Quote
09-23-2012, 12:47 AM
#16
Dan is offline Dan
Dan's Avatar
Status: Request a custom title
Join date: Feb 2005
Location:
Expertise:
Software:
 
Posts: 3,164
iTrader: 15 / 86%
 

Dan is an unknown quantity at this point

  Old

I'm not sure what you mean? I am using timestamps however the column names are 'date.'

Reply With Quote
Reply  
Page 2 of 2 < 1 2


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed