Jump to content

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


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!

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.