Jump to content

TRYING TO UNDERSTAND MYSQL QUERY for ZIP CODE COMPARISON


robman2100

Recommended Posts

I am trying to figure out how to grab a

$number=mysql_num_rows($query);

and only get the sum from Zip codes in a group that i have defined such as

$query = mysql_query("SELECT * FROM table WHERE zip ='22303,22304,22305,22306");
echo $number;

 

This is nesscecary since only certain Zip codes are in Certain Counties. I will then Echo the results to each one of the Counties to show the amount of records i have in each County.

Link to comment
Share on other sites

To select records where zip is equal to any of those values

 

So This will allow me to get the sum of the amount of records that equal to the zips i have placed in the database

 

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = mysql_query("SELECT * FROM locator_store WHERE zip IN='22303,22304,22305,22306');
$number=mysql_num_rows($query);


echo $number;

Link to comment
Share on other sites

To count how many records with these sips are use this

 

$query = mysql_query("SELECT COUNT(*) AS zipCount FROM locator_store WHERE zip IN('22303','22304','22305','22306')";
$row = mysql_fetch_assoc($query);
$number = $row['zipCount'];

echo $number;

Link to comment
Share on other sites

To count how many records with these sips are use this

 

$query = mysql_query("SELECT COUNT(*) AS zipCount FROM locator_store WHERE zip IN('22303','22304','22305','22306')";
$row = mysql_fetch_assoc($query);
$number = $row['zipCount'];

echo $number;

 

I get a Syntax error using the code you provided on line 8 which is the $query line. Im not sure what the syntax error means because it says the error is ; . But that dosent make sense since you have to end each command with ;

Link to comment
Share on other sites

Check if you did not forget to put ; at the end of previous line

 

I found what was originaly wrong we didnt close the TAG with a ) lol :)

But now i am getting a error

called

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

 

I dont understand this is so frustrating im so close but so far away.

Link to comment
Share on other sites

I get a Syntax error

 

You also mind telling what that is? I also want to point out you take a look at:

 

$query = mysql_query("SELECT COUNT(*) AS zipCount FROM locator_store WHERE zip IN('22303','22304','22305','22306')";
$row = mysql_fetch_assoc($query);
$number = $row['zipCount'];

echo $number;

 

Now take a look at:

 

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = mysql_query("SELECT * FROM locator_store WHERE zip IN='22303,22304,22305,22306');
$number=mysql_num_rows($query);


echo $number;

 

You notice something?

 

Hint #1:

 

I found what was originaly wrong we didnt close the TAG with a ) lol :)

 

But now i am getting a error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

 

Hint #2:

 

You sure it was )??

Link to comment
Share on other sites

I get a Syntax error

 

You also mind telling what that is? I also want to point out you take a look at:

 

$query = mysql_query("SELECT COUNT(*) AS zipCount FROM locator_store WHERE zip IN('22303','22304','22305','22306')";
$row = mysql_fetch_assoc($query);
$number = $row['zipCount'];

echo $number;

 

Now take a look at:

 

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = mysql_query("SELECT * FROM locator_store WHERE zip IN='22303,22304,22305,22306');
$number=mysql_num_rows($query);


echo $number;

 

You notice something?

 

Hint #1:

 

I found what was originaly wrong we didnt close the TAG with a ) lol :)

 

But now i am getting a error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

 

Hint #2:

 

You sure it was )??

well if you take a look this is what i have so far

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = mysql_query("SELECT (*) AS zip FROM locator_store WHERE zip IN('22303','22304','22305','22306')");
$row = mysql_num_rows($query);
$number = $row['zip'];
echo $number;

and now i am getting that error i posted before

Link to comment
Share on other sites

And

$row = mysql_num_rows($query);

should be

$row = mysql_fetch_assoc($query);

 

Now i get this error?

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in

 

I dont know this is really frustrating me. Im sure its something simple. Its a small Script too. So idk?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.