Re: [PHP] creating a SELECT AND query

2006-04-18 Thread Robin Vickery
On 18/04/06, Ross [EMAIL PROTECTED] wrote:

 $query1= select * from $table_name WHERE sname LIKE '$search_string%' ;

 if ($area=a)  {
 $query1 .= AND area='a';
  }
  else {
   $query1 .=AND area='$area';
   }

Firstly, you're assigning a to area rather than testing whether
$area is a. You need a == operator, not a =.

Secondly, even if you were testing $area properly, you're doing the
same thing in both halves of the if-statement. Which isn't very
useful.

Really, you only need the AND area='?' part if $area is not equal to a:

if ($area != a) {
   $query1 .=  AND area='$area';
}

  -robin

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



Re: [PHP] creating a SELECT AND query

2006-04-18 Thread Richard Lynch
On Tue, April 18, 2006 6:03 am, Ross wrote:
 select name=area class=text id=area
 option value=aAll of Scotland/option
 option value='1'Aberdeen City Counci.../option
/select


 This is what I thought would work..


 $query1= select * from $table_name WHERE sname LIKE '$search_string%'
 ;

 if ($area=a)  {
 $query1 .= AND area='a';

If $area is 'a', they want ALL of Scotland.

Since your table probably has ONLY Scotland in it, you don't want to
restrict anything there.

For sure, the area isn't going to be 'a' in your table, is it?

Cuz the next line or two seem to indicate that area is a number like
'1' for Aberdeen City Council and so on.

If you're thinking of adding, say, Wales, next month/year, then you
need to have a different field from 'area' and put in the restriction
here for getting just Scotland.

If you just plain don't care about adding anything more ever, you can
just take out the line above.

  }
  else {
   $query1 .=AND area='$area';
   }

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




-- 
Like Music?
http://l-i-e.com/artists.htm

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