RE: [PHP-DB] moving though an array..SOLVED

2003-06-26 Thread Aaron Wolski
Hi All,

Solved my problem!

Here's the code in case anyone really cares :P

$col = explode(,,$threadsColumn);

$col_search = (;
for ($i=0;$icount($col);$i++) {
$col_search .= $col[$i]. LIKE
'%$threadsName%';
if ($i != (count($col) - 1)) {
$col_search .=  OR ;
 }
}

$col_search .= );

Thanks again Adam for your spelling error notice!

Aaron

-Original Message-
From: Adam Voigt [mailto:[EMAIL PROTECTED] 
Sent: June 26, 2003 10:26 AM
To: Aaron Wolski
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] moving though an array..

One Thing:

Change $columns[] to $colums, example:

$columns = explode(',',$threadsColumn);


On Thu, 2003-06-26 at 10:23, Aaron Wolski wrote:
 Hi All,
  
 Hopefully someone here can point me in the right direction.
  
 I need to create a SELECT statement based on some criteria select and
 entered into a form.
  
 Form variables:
  
 $threadsColumn = manufactuer,colour;
 $string = n;
  
 Code:
  
 $columns[] = explode(,,$threadsColumn);
  
 $test = (;
  
 for ($i=0;$isizeof($columns);$i++) {
  
 $test .= $columns[$i]. %$string%;
  
 }
  
 $test .= );
  
 echo $test;
  
 What I am attempting to do is create a select statement that would
look
 like (based on form variables):
  
 SELECT * FROM tablename WHERE (manufacturer LIKE %n% OR colour LIKE
%n%)
  
 The information between ( and ) needs to be written in such a manner
 that it scales up or down in options.. depending on what was selected
in
 the form.
  
 ANYONE have some thoughts?
  
 Oh.. when I echo the above code I get this: (Array %h%)
  
 Thanks!
  
 Aaron 
  
-- 
Adam Voigt ([EMAIL PROTECTED])
Linux/Unix Network Administrator
The Cryptocomm Group


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




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



RE: [PHP-DB] moving though an array..SOLVED

2003-06-26 Thread Ford, Mike [LSS]
 -Original Message-
 From: Aaron Wolski [mailto:[EMAIL PROTECTED]
 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;$icount($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: [EMAIL PROTECTED]
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