List:General Discussion« Previous MessageNext Message »
From:Jed Verity Date:September 6 2002 5:42pm
Subject:Re: select statements
View as plain text  
Perhaps your array items don't have quotes? For example...

Is this what your array looks like: $toTxt = array("a","b","c")

Or is it this: $toTxt = array("\'a\'","\'b\'","\'c\'")

For this to work, it needs to be the second one. If necessary, you can just
walk through the array, adding the quotes:

<?
$toTxt = array("a","b","c");

function AddQuotes (&$arrItem,$key) {
    $arrItem = "'$arrItem'";
}

array_walk($toTxt,'AddQuotes');
$toTxt = implode($toTxt,",");

$sql = "select * from table where field value in ($toTxt)";
?>

Does that work? HTH!
Jed

On the threshold of genius, Ian Osterberg wrote:

> Thanks Jed,
> 
> I'm still stuck though
> 
> I did as you suggested
> 
> ----- Original Message -----
> From: "Jed Verity" <jed@stripped>
> To: "julian haffegee" <jules@stripped>; <mysql@stripped>
> Sent: Friday, September 06, 2002 3:42 AM
> Subject: Re: select statements
> 
> 
>> Hello, Jules,
>> 
>> You can use the "value in (a,b,c)" format. If necessary, implode your
> array
>> and do something like this:
>> 
>> SELECT emailAddress FROM subscribers_html WHERE mailingGroup value in
>> ($toText);
>> 
>> Check the documentation, if necessary, for usage of implode and "value
> in".
>> 
>> HTH!
>> Jed
>> 
>> On the threshold of genius, julian haffegee wrote:
>> 
>>> Hi all,
>>> 
>>> I have a database of names and email addresses, that I want to email.
>>> 
>>> $result = mysql_query("SELECT emailAddress FROM subscribers_html WHERE
>>> mailingGroup='$toText'");
>>> 
>>> The select statement needs to return a row when  mailingGroup='$toText',
> but
>>> $toText is an array. How should I write this select to say where
>>> mailingGroup is an element of the array $toText. Currently it works for
>>> arrays with 1 element only.
>>> 
>>> I could turn the array into a string, but I wondered if there was a
> clever
>>> MySQL way of doing it all as a select
>>> 
>>> Thanks for your help!
>>> 
>>> Jules
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> Before posting, please check:
>>>  http://www.mysql.com/manual.php   (the manual)
>>>  http://lists.mysql.com/           (the list archive)
>>> 
>>> To request this thread, e-mail <mysql-thread118892@stripped>
>>> To unsubscribe, e-mail
> <mysql-unsubscribe-jed=veritys.com@stripped>
>>> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>>> 
>>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> Before posting, please check:
>>    http://www.mysql.com/manual.php   (the manual)
>>    http://lists.mysql.com/           (the list archive)
>> 
>> To request this thread, e-mail <mysql-thread118893@stripped>
>> To unsubscribe, e-mail
> <mysql-unsubscribe-rudy.metzger=pareto.nl@stripped>
>> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>> 
>> 
> 
> 

Thread
changing a slave to a master in mysql replicationVicky Gonzalez4 Sep
Re: changing a slave to a master in mysql replicationBhavin Vyas4 Sep
RE: changing a slave to a master in mysql replicationVicky Gonzalez4 Sep
  • Help!! Extreme newbieAl Davis4 Sep
    • Re: Help!! Extreme newbieDicky Wahyu Purnomo4 Sep
    • Re: Help!! Extreme newbieSteven Kreuzer6 Sep
      • select statementsjulian haffegee6 Sep
        • Re: select statementsJed Verity6 Sep
          • Re: select statementsjulian haffegee6 Sep
Re: changing a slave to a master in mysql replicationBhavin Vyas4 Sep
Re: select statementsJed Verity6 Sep