MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMySQL 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 January 8th, 2003, 08:21 AM
itspram itspram is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 1 itspram User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mySQL Where In function

Hi experts,

I am stuck on mysql IN function using variable.

can anybody provide me with source code for
1. HTML form of multiple selection of combo box

and

2. extracting result for selected values using IN function

e.g. category ID selected is 1,2,3,4,5,6....

sql query would be

$rsresult=mysql_query("select * from tablename where fieldname in ????????? ");

but it doesnt work out, I am new to php

Please Help
Thanks In advance

Reply With Quote
  #2  
Old October 8th, 2005, 11:03 AM
yazer yazer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 7 yazer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 24 sec
Reputation Power: 0
I have the same problem
What is the query string that will work like id=1 & id =2?
any help please

Reply With Quote
  #3  
Old October 8th, 2005, 11:07 AM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 11
Code:
SELECT
 foo
FROM
 bar
WHERE
 foo IN (1,2)


Please start new threads instead of attaching your question to old ones.
__________________
"A pawn is the most important piece on the chessboard -- to a pawn"


Reply With Quote
  #4  
Old February 14th, 2007, 06:51 AM
moightyoirish moightyoirish is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2007
Posts: 1 moightyoirish User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 34 sec
Reputation Power: 0
Smile MySQL IN keyword or MySQL IN function or whatever you want to call it

This is a note to help people struggling with the MySQL IN keyword or MySQL IN function or whatever you want to call it.

This won't work
Code:
SELECT * 
FROM tablename 
WHERE 
fieldname IN ('US,UK,GB,CN');

you need to put it as a list of strings like this
Code:
SELECT * 
FROM tablename 
WHERE 
fieldname IN ('US','UK','GB','CN');

This doesn't apply if it's a list of numbers obviously.
I hope this helps someone.
cheers

Reply With Quote
  #5  
Old May 20th, 2007, 01:16 PM
bugart bugart is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2007
Posts: 1 bugart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 27 sec
Reputation Power: 0
ok, but...

>Ok, but, using IN(2,7,3,5) is returnig results in order 2,3,5,7
>How can i get result in 2,7,3,5 order ? :>

Alright, i have found answer..(finaly)

SELECT * FROM table WHERE id IN(2,7,3,5) ORDER BY FIELD(id,2,5,7,8);

Reply With Quote
  #6  
Old May 28th, 2007, 09:33 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 10
IN array

Note that the IN is an array. If you have a large amount of items it may be easier to use IN $array rather than write a long query.

Reply With Quote
  #7  
Old February 7th, 2013, 11:15 AM
engrmudasir engrmudasir is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 1 engrmudasir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 30 sec
Reputation Power: 0
Look for the Syntax

Quote:
Originally Posted by itspram
Hi experts,

I am stuck on mysql IN function using variable.

can anybody provide me with source code for
1. HTML form of multiple selection of combo box

and

2. extracting result for selected values using IN function

e.g. category ID selected is 1,2,3,4,5,6....

sql query would be

$rsresult=mysql_query("select * from tablename where fieldname in ????????? ");

but it doesnt work out, I am new to php

Please Help
Thanks In advance

You must look at the IN keyword in mySQL.
It is like mysql_query("SELECT * FROM tblname WHERE id IN('1','2','3')");
It will work perfectly.

Reply With Quote
  #8  
Old March 1st, 2013, 03:29 AM
coxodoina coxodoina is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 coxodoina User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 56 sec
Reputation Power: 0
I have the same problem

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mySQL Where In function


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap