robman2100 Posted May 20, 2010 Share Posted May 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 20, 2010 Share Posted May 20, 2010 SELECT * FROM table WHERE zip IN (22303,22304,22305,22306) ?? Quote Link to comment Share on other sites More sharing options...
robman2100 Posted May 20, 2010 Author Share Posted May 20, 2010 SELECT * FROM table WHERE zip IN (22303,22304,22305,22306) ?? What is the purpose of the IN? Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 20, 2010 Share Posted May 20, 2010 To select records where zip is equal to any of those values Quote Link to comment Share on other sites More sharing options...
robman2100 Posted May 20, 2010 Author Share Posted May 20, 2010 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; Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 20, 2010 Share Posted May 20, 2010 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; Quote Link to comment Share on other sites More sharing options...
robman2100 Posted May 20, 2010 Author Share Posted May 20, 2010 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 ; Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 20, 2010 Share Posted May 20, 2010 Check if you did not forget to put ; at the end of previous line Quote Link to comment Share on other sites More sharing options...
robman2100 Posted May 20, 2010 Author Share Posted May 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
ignace Posted May 20, 2010 Share Posted May 20, 2010 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 )?? Quote Link to comment Share on other sites More sharing options...
robman2100 Posted May 20, 2010 Author Share Posted May 20, 2010 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 Quote Link to comment Share on other sites More sharing options...
ignace Posted May 20, 2010 Share Posted May 20, 2010 SELECT (*) AS zip should be SELECT count(*) AS zip Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 20, 2010 Share Posted May 20, 2010 And $row = mysql_num_rows($query); should be $row = mysql_fetch_assoc($query); Quote Link to comment Share on other sites More sharing options...
robman2100 Posted May 20, 2010 Author Share Posted May 20, 2010 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? Quote Link to comment Share on other sites More sharing options...
ignace Posted May 21, 2010 Share Posted May 21, 2010 Did you change?? SELECT (*) AS zip should be SELECT count(*) AS zip Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.