Jump to content

display number of places based on region using php


ramyakumar

Recommended Posts

I m writing a code in mysql using php. I have a database based on world.

 

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?

 

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

 

Please help me.

First of all you may need a number of different tables for the different data types, such as two different tables for regions and places.

 

Secondly what experience do you have in PHP? Not exactly sure what your intention is with the PHP code, but not only does it not really check out syntax wise, (you need to use a period instead of comma for concatenate) your html will also appear with a </select> tag after every option, meaning no drop down will appear.

 

Basically, please outline what experience you have, what you are trying to do, and the specific code which is not working. If you are trying to create a very complex application with very limited experience you may want to try something more simple to start off.

I've done something similar but I was using it within a "<ul>" not a dropdown box, try creating a new query within your loop.

 

SELECT DISTINCT place FROM world WHERE region = $r

 

run that query then you can use the mysql_num_rows function to count the results of that query, store it in a variable and then output into your "<select>" statement.

 

something like

 

echo '<option value="',$r,'">'$r ($count)"</option>";

 

im new to php myself so there a good change thats not the best way to do it so.... correct, add or dismiss the above as appropriate.

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.