|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
I have the same problem
What is the query string that will work like id=1 & id =2? any help please |
|
#3
|
|||
|
|||
|
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" |
|
#4
|
|||
|
|||
|
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 ![]() |
|
#5
|
|||
|
|||
|
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); |
|
#6
|
||||
|
||||
|
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.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > mySQL Where In function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|