Jump to content

Recommended Posts

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>

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?

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.