RE: MultSelect ListBox hell!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Stuart Felenstein [mailto:stuart4m@xxxxxxxxx] 
> Sent: 22 September 2004 16:45
> 
> --- "Ford, Mike" <M.Ford@xxxxxxxxxxxxxx> wrote:
> 
> > >    if (is_array($_POST['state'])){
> > >      $sql .= "(";
> > >      $x = 0;
> > >      foreach ($_POST['state'] as $state)
> > >        if ($x == 0){
> > >        $sql.= "state = '$state' ";
> > >        $x=1;
> > >      }else{
> > >         $sql .= " OR state = '$state' ";
> > >     }
> > >     $sql .= ")";
> > 
> > PHP has the very nice implode function to make this
> > much easier:
> > 
> >     $sql = "state='".implode(' OR state=', $_POST['state'])."'";
> > 
> > (If your database supports the IN operator, this is
> > probably even better:
> >     $sql = "state IN ('".implode("','", $_POST['state'])."')"; )
> 
> Sorry, cause I know this is probably a stupid
> question, but what block of code does the implode
> statement replace ?

Everything inside the if(is_array()).  Ummm, that should probably still be a
.= operator, then.  There's also some quotes missing in the original
version, so:

    if (is_array($_POST['state']))
       $sql .= "state='".implode("' OR state='", $_POST['state'])."'";

Cheers!

Mike

---------------------------------------------------------------------
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services, JG125, James
Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS,
LS6 3QS,  United Kingdom
Email: m.ford@xxxxxxxxxxxxxx
Tel: +44 113 283 2600 extn 4730      Fax:  +44 113 283 3211

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux