RE: [PHP] Re: looping over field, keyword arrays to generate sql

From: Date: Mon, 12 May 2003 03:09:27 +0000
Subject: RE: [PHP] Re: looping over field, keyword arrays to generate sql
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147250@lists.php.net to get a copy of this message
Thankyou James, I managed to work out a solution, my problem was I had to loop over two different arrays of field names and keywords so I just made one multidimensional array and then nested the foreach loops, I like the way you strip off the last "OR" neat ) Reagrds, Joseph -----Original Message----- From: James [mailto:james@globalvision.com] Sent: Friday, 9 May 2003 5:36 PM To: php-general@lists.php.net Subject: [PHP] Re: looping over field, keyword arrays to generate sql $fieldWordArray = Array("keyName"=>"keyValue","otherName"=>"otherValue"); foreach ($fieldWordArray as $key=>$value){ $sqlExtension .= "$key LIKE '%$value%' OR "; } $sqlExtension = substr($sqlExtension,0,strlen($sqlExtension)-4); "Joseph Blythe" <joseph@optcom.net.au> wrote in message news:001801c315c4$33b1a7c0$3500a8c0@ws53... > Hey everyone, > > Was wondering if anyone could point me to a algorithm to loop through two > arrays one being a list of keywords and the other a list of field names to > generate part of an sql statement like: > > $sql .= $field " LIKE '%" . $word . "%' OR " > > Have looked at many search scripts and classes but none really have this > part the way I would like it thought maybe someone may alreday have this or > could point me to a good example? > > Any help appreciated, > > Regards, > > Joseph Blythe > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#147250) next »