| | |
Select where clause with "IN"
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2006
Posts: 82
Reputation:
Solved Threads: 0
Hi
I would like to put a list of ids in an array
and loop to select data from a table using
"IN" in the where clause.
I am not having any success getting this to work.
Any suggestions?
Note:I am using Mysql database, apache, linux/Windows
[/php]
I would like to put a list of ids in an array
and loop to select data from a table using
"IN" in the where clause.
I am not having any success getting this to work.
Any suggestions?
Note:I am using Mysql database, apache, linux/Windows
PHP Syntax (Toggle Plain Text)
[php] <? //array with list of friends to display $friend = array('1','2','3','4'); $query = "SELECT first, last, number FROM friend WHERE id IN '$friend'"; $result = mysqli_query($mysqli, $query);
I'm pretty sure it has to be surrounded with quotes, ie.,
sql Syntax (Toggle Plain Text)
SELECT first,last, number FROM friend WHERE id IN ('1','2','3','4')
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
•
•
Hi
I would like to put a list of ids in an array
and loop to select data from a table using
"IN" in the where clause.
I am not having any success getting this to work.
Any suggestions?
Note:I am using Mysql database, apache, linux/Windows
[/php]PHP Syntax (Toggle Plain Text)
[php] <? //array with list of friends to display $friend = array('1','2','3','4'); $query = "SELECT first, last, number FROM friend WHERE id IN '$friend'"; $result = mysqli_query($mysqli, $query);
php Syntax (Toggle Plain Text)
$query = "SELECT first, last, number FROM friend WHERE id IN 'array'";
$friend_implode = implode(",",$friend); Then use it in your query. php Syntax (Toggle Plain Text)
$query = "SELECT first, last, number FROM friend WHERE id IN (".$friend_implode.")";
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- Can someone help me with a complicated search parameters (ASP.NET)
- PHP Mysql "Where" statement (PHP)
- Syntax error in "like" in sql statement (ASP.NET)
Other Threads in the PHP Forum
- Previous Thread: how to reset md5 encrypted password
- Next Thread: i am trying to attach a file with mail and getting following error.how can i solve?
Views: 1297 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube






