I'm confused

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

I'm confused

Post by keithh0427 »

patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Below is a snippet of code that has me confused.

Code: Select all

$filterCode = "WHERE city = '$city' and state = '$st'";

$getZONE = "SELECT zone FROM zones $filtercode";
$getCount = mysql_query( $getZONE );
$countnum = mysql_num_rows( $getCount );

if ($countnum == 0) {
$zone = 99;

} else {
$zone = mysql_query( $getZONE );
}
The code always returns 99 for $zone. When I view $filtercode later on in the script, there's nothing there. When I view $getZONE, all I get is "SELECT zone FROM zones".

Could someone shed some light on this and get me out of the dark? I can't see the forest right now because there are too many trees in the way.
patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

$filtercode is not the same as $filterCode

You should also note that if your query returns any rows then your code snippet executes the query again (and $zone becomes a resource identifier (is this the desired behaviour)), there is no point in this as you already have the result set.
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

Post by keithh0427 »

patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Thanks.  I just could not see the "C" instead of the "c".  Would this code work better (based on your suggestion)?

Code: Select all

$filterCode = "WHERE city = '$city' and state = '$st'";

$getZONE = "SELECT zone FROM zones $filterCode";
$zone = mysql_query( $getZONE );
$countnum = mysql_num_rows( $zone );

if ($countnum == 0) {
$zone = 99;
}
patrikG | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Post Reply