frustration is setting in

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

frustration is setting in

Post by keithh0427 »

I've been working and re-working this for hours and getting nowhere fast. Here's a snippet of code I'm trying to get to work.

Code: Select all

$query = "SELECT zone FROM zones WHERE city = '$city' and state = '$st'";
$result = mysql_query( $query );
$rows = mysql_num_rows($result);

if ($rows == 0) {
  $zone = 99;
  }
  else {
    $zone = $result;
    }
I have a table "zones" with one zone for each city,state combination. If I echo $query, I get the following:

SELECT zone FROM zones WHERE city = 'Aurora' and state = 'IL'

If I run that query directly from the database, the resulting zone is 5. However, from the program, the resulting zone is 99. It's always 99. I've tried several approaches including putting the result into an array, but I always get 99 instead of the actual zone.

Would someone point me in the right direction? I know it's me, but I cannot figure out why it doesn't work.
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

Primarily you probably don't want to put $result into $zone - $result is just resource id, not the actual data, use mysql_fetch_x for that. And when there is not such record (Aurora/IL) then you'll get 99
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

Post by keithh0427 »

I'll give that a try, but why does it always enter the loop that sets $zone = 99? Shouldn't $rows be 1?
keithh0427
Forum Newbie
Posts: 15
Joined: Thu Dec 16, 2004 8:17 am

Post by keithh0427 »

Problem solved.

Thanks!
User avatar
MarK (CZ)
Forum Contributor
Posts: 239
Joined: Tue Apr 13, 2004 12:51 am
Location: Prague (CZ) / Vienna (A)
Contact:

Post by MarK (CZ) »

keithh0427 wrote:I'll give that a try, but why does it always enter the loop that sets $zone = 99? Shouldn't $rows be 1?
Not if you don't have any entry that matches your criteria
Post Reply