#1
  1. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    I am putting together a database that includes states and cities... Each state has multiple listings in my database and also, each city has multiple listings in my database... When I call for a list of cities, I only want the cities to appear once, not multiple times... how do I do this... here is part of my script... I am really new at this so please forgive me if it is a really easy answer...

    Thank you...

    $result = mysql_query("SELECT * FROM $state",$db);

    if ($myrow = mysql_fetch_array($result)) {


    ?>

    <form method="post" action="cities.php3">
    <p>
    <select name="state"><?php


    printf("<option selected>
    $staten");?>

    </select>

    <select name="cities">
    <option selected>Select a City</option><?php
    do {

    printf("<option>%sn", $myrow["City"]);

    } while ($myrow = mysql_fetch_array($result));

    echo "n";

    ?>

    </select>
  2. #2
  3. No Profile Picture
    Hans
    Guest
    Devshed Newbie (0 - 499 posts)
    How about using SELECT DISTINCT? Maybe that solves your problem.
  4. #3
  5. No Profile Picture
    Darguz
    Guest
    Devshed Newbie (0 - 499 posts)
    As Hans says, the DISTINCT keyword will do it for you. An example:

    $Query = "SELECT DISTINCT City from State";

    ------------------
    Alan Little
    Holotech Web Design
    www.holotech.net/


    [This message has been edited by Darguz (edited 12-08-99).]

Similar Threads

  1. Query for Retrieving Results on a Quartely basis
    By srinig2002 in forum Database Management
    Replies: 1
    Last Post: February 6th, 2004, 04:39 PM
  2. Using sessions for search / results pages
    By Quirk in forum PHP Development
    Replies: 10
    Last Post: December 15th, 2003, 09:36 PM
  3. Select box selected months
    By TuxLives in forum PHP Development
    Replies: 10
    Last Post: December 15th, 2003, 08:54 AM
  4. Limit results on 'left join' query
    By tippiedog in forum MySQL Help
    Replies: 1
    Last Post: November 12th, 2003, 08:58 AM
  5. Search & Display PEAR DB results
    By nickcwj in forum PHP Development
    Replies: 2
    Last Post: September 25th, 2003, 03:09 AM

IMN logo majestic logo threadwatch logo seochat tools logo