let us assume
$ssn={001,002,003}
and
i want to execute ike
select username from city where ssn in (001,002,003)
but i am having the vaues inside array $ssn i want to do like this
select username from city where ssn in ($ssn)
now tell me how do i convert $ssn to 001,002,003 please suggest if i could use list.
php array for mysql statement
Moderator: General Moderators
-
lokesh_kumar_s
- Forum Commoner
- Posts: 48
- Joined: Mon Apr 13, 2009 5:39 am
- Contact:
Re: php array for mysql statement
You need to destruct your array into a string. There is no handy premade function to do this. You should loop through the array and append them to a string.
Code: Select all
$string = '';
$first = true;
foreach($array as $val)
{
if(!$first)
$string .= ', ';
$string .= $val
} - AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: php array for mysql statement
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: php array for mysql statement
Well there ya go