Forum Moderators: coopster

Message Too Old, No Replies

Operator of &&

how to use the &&

         

xbl01234

2:31 pm on Oct 5, 2006 (gmt 0)

10+ Year Member



Hello;
I got a problem to use the && in php scrip.
for the

when i use the && in the following statment, it does not work. and i have a massage with "Error processing request - check your query".
if(($SC!=null)&&($C==null)&&($Ci==null))
$result = mysql_query("select * from Customer where Country=" . "'$D'" . " and State=" . "'$SC'" . " and BType=" . "'$E'");

but when i use && in the following, they work.
if($SC!=null)
$result = mysql_query("select * from Customer where Country=" . "'$D'" . " and State=" . "'$SC'" . " and BType=" . "'$E'");

and
if(($C!=null)&&($B!=null)&&($Ci!=null)&&($SC!=null))
$result = mysql_query("select * from Customer where Country=" . "'$D'" . " and City=" . "'$F'" . " and State=" . "'$SC'" . " and Area=" . "'$A'" . " and BType=" . "'$E'");

both about are work

Could you tell me why, please

jatar_k

4:00 pm on Oct 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld xbl01234,

if you are testing using the exact same vars then version 1 and 2 are exactly the same and should both perform equally, as far as the query goes.

the first one says
if $SC is not null and $C is equal to null and $Ci is equal to null

the second says
if $SC is not null

the queries are exactly the same, so the added tested values only make a difference in whether the query will be executed, not in it's performance. Neither of the added tested values are used in the query.

what you should probably do is add some error checking to those queries so you can get the actual error from mysql and split out your query construction, this will help debugging as well. Your queries are also concatenated in a very strange way. Take a look at this

$q = "select * from Customer where Country='" . $D . "' and State='" . $SC . "' and BType='" . $E . "'";
// echo '<p>',$q;
$result = mysql_query($q) or die ('query at line xx died: ' . mysql_error());

  • I moved the single quotes in your query concatenation
  • you should add the line number to the or die, or some other recognizable piece of data since I gather you have more than one query in the script
  • you can uncomment the echo statement to look at the query you are sending to mysql
  •