| | |
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?
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary bounce broken cakephp checkbox class cms code codingproblem combobox cron curl database date display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla js limit link login loop mail menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion regex remote return script search server sessions smash sms soap source space sql syntax system table tutorial up-to-date update upload url validation validator variable video web webapplications websitecontactform xml youtube






