ramyakumar Posted November 14, 2009 Share Posted November 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/181469-display-number-of-places-based-on-region-using-php/ Share on other sites More sharing options...
joquius Posted November 14, 2009 Share Posted November 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/181469-display-number-of-places-based-on-region-using-php/#findComment-957349 Share on other sites More sharing options...
mattyvx Posted November 14, 2009 Share Posted November 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/181469-display-number-of-places-based-on-region-using-php/#findComment-957367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.