gabrielkolbe Posted October 10, 2007 Share Posted October 10, 2007 Hi, I have a property website, on it I have a drop down box where all the for cities. On the drop down box is displayed all the cities of the properties on the database, I also want to count how many properties there are for each city and then display the number next to the city, so that users can know how many properties are available for each city. ( I can count the amount of times each city appears in the database ) Here is my code so far, I would appreciate someone to help me here!! Don't be confused by the code I have tried various ways of making this work, I can display the cities... NOTE: That I would probably be easier to push the cities in an array, use the unique array function to only display 1 of each city, BUT before this count the amount of times a city appear....How to do this, i don't know.. <select name="city" class="formfields"> <option value="All" selected>All Cities</option> <? //$i = 0; $cities = array(); $query = "SELECT * FROM right_prop_1 order by city"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { array_push($cities, $row['city']); //for ($i = 1; $i <= 10; $i++) { // echo $i; //} //if (array_key_exists($row['city'], $cities)) { //$i=$i+1; echo '<option>' . $row['city'] .' [' . $i . ']</option>'; } } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/72590-display-and-count-query/ Share on other sites More sharing options...
gabrielkolbe Posted October 10, 2007 Author Share Posted October 10, 2007 Sorry, my writing was not clear, here we go again.. Hi, I have a property website, on it I have a drop down box where all cities are displayed. I also want to count how many properties there are for each city and then display the number next to the city, so that users can know how many properties are available for each city. Here is my code so far, I would appreciate someone to help me here!! Don't be confused by the code I have tried various ways of making this work. NOTE: That I would probably be easier to push the cities in an array, use the unique array function to only display 1 of each city, BUT before this, count the amount of times each city appears.... <select name="city" class="formfields"> <option value="All" selected>All Cities</option> <? //$i = 0; $cities = array(); $query = "SELECT * FROM right_prop_1 order by city"; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { array_push($cities, $row['city']); //for ($i = 1; $i <= 10; $i++) { // echo $i; //} //if (array_key_exists($row['city'], $cities)) { //$i=$i+1; echo '<option>' . $row['city'] .' [' . $i . ']</option>'; } } ?> </select> Quote Link to comment https://forums.phpfreaks.com/topic/72590-display-and-count-query/#findComment-366056 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.