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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.