column dependent on row value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ramya4myself
Forum Newbie
Posts: 7
Joined: Sat Nov 07, 2009 2:46 pm

column dependent on row value

Post 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
User avatar
iankent
Forum Contributor
Posts: 333
Joined: Mon Nov 16, 2009 4:23 pm
Location: Wales, United Kingdom

Re: column dependent on row value

Post by iankent »

would this do it?

Code: Select all

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