Page 1 of 1

column dependent on row value

Posted: Sat Nov 14, 2009 1:25 am
by ramya4myself
I m writing a code in mysql using php. I have a database based on world.

Code: Select all

CREATE TABLE world (
place    VARCHAR(50) NOT NULL,
region VARCHAR(15) NOT NULL,
distance     VARCHAR(20),
);
I have a code which have particular regions but then I want it to also display number of places based on region. I have written a query which is working but I want it to display region and number of places in that region. How do I do this with my code?

Code: Select all

foreach ($regions as $r)
{
 echo '<option value="',$r,'">',$r,"</option>";
 echo '</select></p>';
 }
Please help me.

Thanks

Re: column dependent on row value

Posted: Tue Nov 17, 2009 6:54 am
by iankent
would this do it?

Code: Select all

SELECT region, count(place) as places FROM world GROUP BY region;