473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Pass a PHP array into Mysql 'IN' clause

bilibytes
128 100+
Hi there,

is it possible to pass a PHP array to get some data matching in a Mysql Table?

lets say i have a list of names that i get from PHP into an array:

Expand|Select|Wrap|Line Numbers
  1. $php_array = array(0=>'john', 1=>'marcus', 2=>'robert', 3=>'samuel'...)
and i want to know which of these are in my Table.

could i do:

Expand|Select|Wrap|Line Numbers
  1. SELECT user_id
  2. FROM users
  3. WHERE user_name IN ($php_array)
i don't know if mysql can make it..

is there a way to perform this?


thank you,

best regards
Nov 14 '08 #1
3 39949
Atli
5,058 Expert 4TB
Hi.

You could try the implode function.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $array = array("first", "second", "third");
  3. $list = "'". implode("', '", $array) ."'";
  4. echo $list; // Outputs: 'first', 'second', 'third'
  5. ?>
  6.  
The $list string could then be used in the IN function.
Nov 14 '08 #2
bilibytes
128 100+
ok great, thankyou very much!

bilibytes
Nov 18 '08 #3
perfect, thanks very much
Jan 12 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: John | last post by:
I would like to pass array variables between URLs but I don't know how. I know its possible with sessions, but sessions can become useless if cookies are disabled. I have unsuccessfully tried...
1
by: Berend | last post by:
I am trying to pass multi values into a where clause with an in clause in a store procedure to use in a Crystal report. This can change depending on the user. Maybe there is another way to pass...
41
by: Berk Birand | last post by:
Hi, I am just learning about the array/pointer duality in C/C++. I couldn't help wondering, is there a way to pass an array by value? It seems like the only way to do is to pass it by...
5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
9
by: DFS | last post by:
You might also find other uses ========================================================= Public Function getSelections(selType As String, selSeparator As Boolean, selList As ListBox, selCol As...
10
by: tony | last post by:
i'm trying to itterate through an array that contains the names of the global arrays eg: $myarray = array("\$_GET", "\$_SERVER"); and so on The problem Im having is calling a function...
5
by: deane.barker | last post by:
Consider this SQL: SELECT my_field FROM my_table WHERE my_field IN ('value2', 'value1', 'value3') Simple enough, but is there anyway to specify that the result should be ordered exactly like...
2
by: tarunsanju15 | last post by:
Hi, I am writing a dynamic query in which i have to select a records depend upon the no. of values entered by user like: select * from _table where _tableColumn IN (values entered by user) the...
0
by: Mark C. Stock | last post by:
"Mark C. Stock" <mcstockX@Xenquery .comwrote in message news:... | | "Berend" <Berend.Brinkhuis@evatone.comwrote in message | news:bdd9ac20.0401271301.22cdb65e@posting.google.com... | | I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.