RE: [PHP-DB] moving though an array..SOLVED
| From: | Ford, Mike [LSS] | Date: | Thu, 26 Jun 2003 16:33:39 +0000 |
| Subject: | RE: [PHP-DB] moving though an array..SOLVED | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-28914@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Aaron Wolski [mailto:aaronjw@martekbiz.com]
> Sent: 26 June 2003 16:12
>
> Solved my problem!
>
> Here's the code in case anyone really cares :P
>
> $col = explode(",",$threadsColumn);
>
> $col_search = "(";
> for ($i=0;$i<count($col);$i++) {
>
> $col_search .= $col[$i]." LIKE
> '%$threadsName%'";
> if ($i != (count($col) - 1)) {
> $col_search .= " OR ";
> }
> }
>
> $col_search .= ")";
Yes, that's about how I'd do it -- you may, however, be interested in this variation on
the theme:
$col = explode(",",$threadsColumn);
$col_search = array();
foreach ($col as $col_name) {
$col_search[] = "$col_name LIKE '%$threadsName%'";
$col_search = "(" . implode(' OR ', $col_search) . ")";
A completely different approach might be to do it like this:
$col_search = "("
. str_replace(',',
" LIKE '%$threadsName%' OR ",
$threadsColumn)
. " LIKE '%$threadsName%'"
. ")";
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211