Jump to content

[SOLVED] How to count the # if instances an ID is in a table?


BadGoat

Recommended Posts

Hi!

 

I am trying to count the # of instances where an ID appears in a table. I have a city table where each city has an id and a region id, a region table where the region has an id. I want to be able to count the # of cities are in a region by id. Everything I've tried is either 0 or 4, no clue how I got 4, even though I verified that none of the regions had only 4 cities.

 

Here's a  bit of code, where I'd been trying to get it to work.


<tr>
    <td>'.$row['region'].' contains ';
    $query1 = "SELECT SUM(region_id) AS totalcons FROM e_city WHERE  region_id = '$region_id'";
    $result = mysql_query($query1);
    $r = mysql_fetch_array($result);
echo number_format($totalcons);
echo' Cities.</td>
</tr>

 

Please point me in the right direction. Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.