Page 1 of 1

frustration is setting in

Posted: Thu Dec 16, 2004 10:15 am
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.

Posted: Thu Dec 16, 2004 10:55 am
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

Posted: Thu Dec 16, 2004 11:02 am
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?

Posted: Thu Dec 16, 2004 11:25 am
by keithh0427
Problem solved.

Thanks!

Posted: Thu Dec 16, 2004 11:59 am
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