PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 21st, 2004, 06:11 AM
sirtom sirtom is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 11 sirtom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 57 m 11 sec
Reputation Power: 0
Help with WHERE clause in QUERY

I dont know how to do it!

I got first query working all rigth! And it gives me in result

list of themes that match the where clause


PHP Code:
 $theme_sql "SELECT id, name FROM themes WHERE group = 2 ORDER BY id"
$theme_q mysql_query ($theme_sql); 
$theme_sql mysql_num_rows($theme_q); 
for (
$i 0$i<$theme_sql$i++) {  
$theme_res mysql_fetch_array ($theme_q); 
$theme_id =  $theme_res[id]; 
$theme_name $theme_res[name]; 
if (
$i+1==$theme_sql) { 
print 
"$theme_name ($theme_id)"
 }  
else { 
print 
"$theme_name ($theme_id) | "
  } 
 } 



Now I want to run second query which should give me in result all subthemes that belong to those selected themes from first query.


PHP Code:
 $st_sql "SELECT sname FROM subthemes WHERE belong_ref = $theme_id"



But I only get results where belong_ref = to the last id in list that I got from first guery.

How can I make in WHERE clause make for example belong_ref be IN (10000, 11000 12000) those id-s that I got in first query.

Reply With Quote
  #2  
Old October 24th, 2004, 01:33 AM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
OK, try this...

PHP Code:
 $theme_sql "SELECT id, name FROM themes WHERE group = 2 ORDER BY id"
$theme_q mysql_query ($theme_sql); 
$theme_sql mysql_num_rows($theme_q); 
for (
$i 0$i<$theme_sql$i++) {  
$theme_res mysql_fetch_array ($theme_q); 
$theme_id =  $theme_res[id]; 
$theme_name $theme_res[name]; 
if (
$i+1==$theme_sql) { 
$ids[] = $theme_id;
print 
"$theme_name ($theme_id)"
}  
else { 
print 
"$theme_name ($theme_id) | "
  } 


$st_sql "SELECT sname FROM subthemes WHERE belong_ref IN (".implode(",",$ids).")"


Bingo !

__________________
The deal is not to know everything, but to know the email of the one who does.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Help with WHERE clause in QUERY


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT