Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with syntax please..

Status
Not open for further replies.

wudz

Programmer
Mar 28, 2001
135
GB
Hi,

Thought I had a simple logic problem, but uncertain of my syntax/ logic.

The problem is that 'local_area 6' is always selected even though the test query town displayed is in 'local_area 3' which is correct.

Is '||' equal to OR which is what I require. Is there a shorter way of achiving the same result when the code is corrected...


Newbie John


<code>

$area = mysql_result ( $result, 0, "town" );
$TPL_area = $area;

if(($area ='Colne')||($area ='Nelson') || ($area ='Barrowford') || ($area ='Brierfield')) {
$local_area = 1;
}
if (($area ='Burnley') || ($area ='Padiham')||($area ='Fence')) {
$local_area = 2;
}
if (($area ='Hapton')|| ($area ='Accrington')|| ($area ='Oswaldtwistle')|| ($area ='Church')|| ($area ='Baxenden')) {
$local_area = 3;
}


if (($area ='Great Harwood')|| ($area ='Rishton')) {
$local_area = 4;

}
if (($area ='Blackburn')|| ($area ='Mellor')|| ($area ='Darwen')) {
$local_area = 5;

}
if (($area ='Chorley')|| ($area ='Bamber Bridge')|| ($area ='Leyland')) {
$local_area = 6;
}
$TPL_locationnum = $local_area;

</code>
 
You're using the wrong operator.

In PHP, "=" is used exclusively for assignments. If you want to compare, you must use "==".



Want the best answers? Ask the best questions! TANSTAAFL!
 
Hi,
Just to clarify my last post.

No matter what town is held in variable $area it always displays $local_area as being 6....

Cheers
Newbie John
 
Cheers Sleipnir....crossed posts....I live and learn..Thanks again for all your help.

Cheers John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top