iceman023 Posted July 18, 2009 Share Posted July 18, 2009 I have a dropdown menu with a list of cities. I want the number of photos to be next to the city so that you know how many there are prior to your click.. I did it this way but i know its NOT the best choice BUT it DOES work... Any input on how to help/improve this.. $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Albuquerque\''); $Albuquerque = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Arlington\''); $Arlington = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Atlanta\''); $Atlanta = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Austin\''); $Austin = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Baltimore\''); $Baltimore = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Boston\''); $Boston = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Cleveland\''); $Cleveland = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Chicago\''); $Chiago = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Colorado Springs\''); $ColoradoSprings = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Columbus\''); $Columbus = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Dallas\''); $Dallas = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Denver\''); $Denver = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Detroit\''); $Detroit = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'ElPaso\''); $ElPaso = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'FortWorth\''); $FortWorth = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Fresno\''); $Fresno = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Honolulu\''); $Honolulu = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Houston\''); $Houston = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Indianapolis\''); $Indianapolis = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Jacksonville\''); $Jacksonville = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'KansasCity\''); $KansasCity = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'LasVegas\''); $LasVegas = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'LongBeach\''); $LongBeach = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'LosAngeles\''); $LosAngeles = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Louisville\''); $Louisville = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Memphis\''); $Memphis = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Mesa\''); $Mesa = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Miami\''); $Miami = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Milwaukee\''); $Milwaukee = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Minneapolis\''); $Minneapolis = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Nashville\''); $Nashville = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'NewOrleans\''); $NewOrleans = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'NewYork\''); $NewYork = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Oakland\''); $Oakland = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'OklahomaCity\''); $OklahomaCity = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Omaha\''); $Omaha = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Philadelphia\''); $Philadelphia = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Phoenix\''); $Phoenix = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Portland\''); $Portland = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Raleigh\''); $Raleigh = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Sacramento\''); $Sacramento = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'SanAntonio\''); $SanAntonio = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'SanDiego\''); $SanDiego = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'SanFrancisco\''); $SanFrancisco = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'SanJose\''); $SanJose = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Seattle\''); $Seattle = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Tucson\''); $Tucson = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'Tulsa\''); $Tulsa = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'VirginiaBeach\''); $VirginiaBeach = mysql_num_rows($sql); $sql = mysql_query('SELECT (City)FROM Photos WHERE City=\'WashingtonDC\''); $WashingtonDC = mysql_num_rows($sql); <div align="center" class="style1"> <ul id="MenuBar1" class="MenuBarHorizontal"> <li><a href="index.php" title="Home">Home</a></li> <li><a href="AboutUs.php">About Us</a></li> <li><a href="#" class="MenuBarItemSubmenu">Cities</a> <ul> <li><a href="Cities.php?City=Albuquerque" title="Albuquerque" target="_self" >Albuquerque (<?php echo $Albuquerque; ?>)</a></li> <li><a href="Cities.php?City=Arlington" title="Arlington" target="_self" >Arlington (<?php echo $Arlington; ?>)</a></li> <li><a href="Cities.php?City=Atlanta" title="Atlanta" target="_self" >Atlanta (<?php echo $Atlanta; ?>)</a></li> <li><a href="Cities.php?City=Austin" title="Austin" target="_self" >Austin (<?php echo $Austin; ?>)</a></li> <li><a href="Cities.php?City=Baltimore" title="Baltimore" target="_self" >Baltimore (<?php echo $Baltimore; ?>)</a></li> <li><a href="Cities.php?City=Boston" title="Boston" target="_self" >Boston (<?php echo $Boston; ?>)</a></li> <li><a href="Cities.php?City=Cleveland" title="Cleveland" target="_self" >Cleveland (<?php echo $Cleveland; ?>)</a></li> <li><a href="Cities.php?City=Chicago" title="Chicago" target="_self" >Chicago (<?php echo $Chiago; ?>)</a></li> <li><a href="Cities.php?City=ColoradoSprings" title="Colorado Springs" target="_self" >Colorado Springs (<?php echo $ColoradoSprings; ?>)</a></li> <li><a href="Cities.php?City=Columbus" title="Columbus" target="_self" >Columbus (<?php echo $Columbus; ?>)</a></li> <li><a href="Cities.php?City=Dallas" title="Dallas" target="_self" >Dallas (<?php echo $Dallas; ?>)</a></li> <li><a href="Cities.php?City=Denver" title="Denver" target="_self" >Denver (<?php echo $Denver; ?>)</a></li> <li><a href="Cities.php?City=Detroit" title="Detroit" target="_self" >Detroit (<?php echo $Detroit; ?>)</a></li> <li><a href="Cities.php?City=ElPaso" title="El Paso" target="_self" >El Paso (<?php echo $ElPaso; ?>)</a></li> <li><a href="Cities.php?City=FortWorth" title="Fort Worth" target="_self" >Fort Worth (<?php echo $FortWorth; ?>)</a></li> <li><a href="Cities.php?City=Fresno" title="Fresno" target="_self" >Fresno (<?php echo $Fresno; ?>)</a></li> <li><a href="Cities.php?City=Honolulu" title="Honolulu" target="_self" >Honolulu (<?php echo $Honolulu; ?>)</a></li> <li><a href="Cities.php?City=Houston" title="Houston" target="_self" >Houston (<?php echo $Houston; ?>)</a></li> <li><a href="Cities.php?City=Indianapolis" title="Indianapolis" target="_self" >Indianapolis (<?php echo $Indianapolis; ?>)</a></li> <li><a href="Cities.php?City=Jacksonville" title="Jacksonville" target="_self" >Jacksonville (<?php echo $Jacksonville; ?>)</a></li> <li><a href="Cities.php?City=KansasCity" title="Kansas City" target="_self" >Kansas City (<?php echo $KansasCity; ?>)</a></li> <li><a href="Cities.php?City=LasVegas" title="Las Vegas" target="_self" >Las Vegas (<?php echo $LasVegas; ?>)</a></li> <li><a href="Cities.php?City=Long Beach" title="Long Beach" target="_self" >Long Beach (<?php echo $LongBeach; ?>)</a></li> <li><a href="Cities.php?City=LosAngeles" title="Los Angeles" target="_self" >Los Angeles (<?php echo $LosAngeles; ?>)</a></li> <li><a href="Cities.php?City=Louisville" title="Louisville" target="_self" >Louisville (<?php echo $Louisville; ?>)</a></li> <li><a href="Cities.php?City=Memphis" title="Memphis" target="_self" >Memphis (<?php echo $Memphis; ?>)</a></li> <li><a href="Cities.php?City=Mesa" title="Mesa" target="_self" >Mesa (<?php echo $Mesa; ?>)</a></li> <li><a href="Cities.php?City=Miami" title="Miami" target="_self" >Miami (<?php echo $Miami; ?>)</a></li> <li><a href="Cities.php?City=Milwaukee" title="Milwaukee" target="_self" >Milwaukee (<?php echo $Milwaukee; ?>)</a></li> <li><a href="Cities.php?City=Minneapolis" title="Minneapolis" target="_self" >Minneapolis (<?php echo $Minneapolis; ?>)</a></li> <li><a href="Cities.php?City=Nashville" title="Nashville" target="_self" >Nashville (<?php echo $Nashville; ?>)</a></li> <li><a href="Cities.php?City=NewOrleans" title="New Orleans" target="_self" >New Orleans (<?php echo $NewOrleans; ?>)</a></li> <li><a href="Cities.php?City=NewYork" title="New York" target="_self" >New York (<?php echo $NewYork; ?>)</a></li> <li><a href="Cities.php?City=Oakland" title="Oakland" target="_self" >Oakland (<?php echo $Oakland; ?>)</a></li> <li><a href="Cities.php?City=Oklahoma City" title="Oklahoma City" target="_self" >Oklahoma City (<?php echo $OklahomaCity; ?>)</a></li> <li><a href="Cities.php?City=Omaha" title="Omaha" target="_self" >Omaha (<?php echo $Omaha; ?>)</a></li> <li><a href="Cities.php?City=Philadelphia" title="Philadelphia" target="_self" >Philadelphia (<?php echo $Philadelphia; ?>)</a></li> <li><a href="Cities.php?City=Phoenix" title="Phoenix" target="_self" >Phoenix (<?php echo $Phoenix; ?>)</a></li> <li><a href="Cities.php?City=Portland" title="Portland" target="_self" >Portland (<?php echo $Portland; ?>)</a></li> <li><a href="Cities.php?City=Raleigh" title="Raleigh" target="_self" >Raleigh (<?php echo $Raleigh; ?>)</a></li> <li><a href="Cities.php?City=Sacramento" title="Sacramento" target="_self" >Sacramento (<?php echo $Sacramento; ?>)</a></li> <li><a href="Cities.php?City=SanAntonio" title="San Antonio" target="_self" >San Antonio (<?php echo $SanAntonio; ?>)</a></li> <li><a href="Cities.php?City=SanDiego" title="San Diego" target="_self" >San Diego (<?php echo $SanDiego; ?>)</a></li> <li><a href="Cities.php?City=SanFrancisco" title="San Francisco" target="_self" >San Francisco (<?php echo $SanFrancisco; ?>)</a></li> <li><a href="Cities.php?City=SanJose" title="San Jose" target="_self" >San Jose (<?php echo $SanJose; ?>)</a></li> <li><a href="Cities.php?City=Seattle" title="Seattle" target="_self" >Seattle (<?php echo $Seattle; ?>)</a></li> <li><a href="Cities.php?City=Tucson" title="Tucson" target="_self" >Tucson (<?php echo $Tucson; ?>)</a></li> <li><a href="Cities.php?City=Tulsa" title="Tulsa" target="_self" >Tulsa (<?php echo $Tulsa; ?>)</a></li> <li><a href="Cities.php?City=Virginia Beach" title="Virginia Beach" target="_self" >Virginia Beach (<?php echo $VirginiaBeach; ?>)</a></li> <li><a href="Cities.php?City=Washington DC" title="Washington DC" target="_self" >Washington DC (<?php echo $WashingtonDC; ?>)</a></li> </ul> </li> </ul> </div> Quote Link to comment https://forums.phpfreaks.com/topic/166407-solved-css-dropdown-menu-with-select-statment/ Share on other sites More sharing options...
GingerRobot Posted July 18, 2009 Share Posted July 18, 2009 If all the cities are required and all the cities have some associated photos, you could go with this: <?php $sql = "SELECT COUNT(*) as cnt, City FROM Photos GROUP BY City ORDER BY City ASC"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); if($result){ while($row = mysql_fetch_assoc($result)){ echo '<li><a href="Cities.php?City=' . $row['City'] . '" title="' . $row['City'] . '" target="_self" >' . $row['City'] . '(' . $row['cnt'] . ')</a></li>' . "\n"; } } ?> If not, then do you have another table containing the cities? Quote Link to comment https://forums.phpfreaks.com/topic/166407-solved-css-dropdown-menu-with-select-statment/#findComment-877511 Share on other sites More sharing options...
GingerRobot Posted July 18, 2009 Share Posted July 18, 2009 I should probably explain that the above code will show the links for city only if there is at least one photo for it. If not, it won't be displayed. Perhaps this is the behavior you're after, but I don't know. Quote Link to comment https://forums.phpfreaks.com/topic/166407-solved-css-dropdown-menu-with-select-statment/#findComment-877514 Share on other sites More sharing options...
iceman023 Posted July 18, 2009 Author Share Posted July 18, 2009 no i like that idea alot. (only if there is a photo) Can i just copy and past that code and you think it will work??? Thanks alot! Quote Link to comment https://forums.phpfreaks.com/topic/166407-solved-css-dropdown-menu-with-select-statment/#findComment-877755 Share on other sites More sharing options...
iceman023 Posted July 18, 2009 Author Share Posted July 18, 2009 ok yes that code works BUT how do i do this as a dropdown list with CSS. Each city has to be an LI right??? Quote Link to comment https://forums.phpfreaks.com/topic/166407-solved-css-dropdown-menu-with-select-statment/#findComment-877762 Share on other sites More sharing options...
GingerRobot Posted July 19, 2009 Share Posted July 19, 2009 Are you asking how to create a select box? If so, i'd recommend w3School's tutoral: http://www.w3schools.com/TAGS/tag_Select.asp Quote Link to comment https://forums.phpfreaks.com/topic/166407-solved-css-dropdown-menu-with-select-statment/#findComment-877996 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.