How can I do this in a better way?
$query = mysql_query("SELECT * FROM table WHERE region='example1'");
$num_rows_example1 = mysql_num_rows($query);
$query = mysql_query("SELECT * FROM table WHERE region='example2'");
$num_rows_example2 = mysql_num_rows($query);
$query = mysql_query("SELECT * FROM table WHERE region='example3'");
$num_rows_example3 = mysql_num_rows($query);
Maybe with an Array and Foreach?
Thanks!
Your query could be
And now you only have one query to perform, which returns the number of rows for each region!
Now you can perform some PHP magic using your array of
PLEASE NOTE You should stop using
mysql_*functions. They’re being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you’re not sure which one to use, read this SO article.