#1
  1. No Profile Picture
    newmediaarts
    Guest
    Devshed Newbie (0 - 499 posts)
    Basicly I'm looking for a function that would do the following.

    MySQL Query Returns...
    1 - Capital High School - Olympia
    2 - Middle High School - Olympia
    3 - Central High School - Seattle
    4 - Midtown High School - Olympia

    The PHP program would then output...
    Olympia
    Seattle

    Basicly chopping any repeats of the city.
    This really needs to be handled through php because were are trying to limit the MySQL calls as they slow down the server (server will recieve between 250,000 and 500,000 queries daily)

    ------------------
    Luke Bowerman
    new media arts
    http://www.judebowerman.com/nma
  2. #2
  3. No Profile Picture
    moderator
    Guest
    Devshed Newbie (0 - 499 posts)
    Keep in mind that there are many ways you could do it, however here is one:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    while($row=mysql_fetch_array($queryResult)){
    if(!$city){$city[0]=$row["cityName"];} #First city is automatically entered
    else{
    $i=0;
    $cityMax=count($city);
    $cityExists=0;
    while($i<$cityMax&&!$cityExists){
    if($city[$i]==$row["cityName"]){$cityExists=1;}
    }
    if(!$cityExists){$city[]=$row["cityName"];} #if city not already in list then put it in
    }
    }
    ?>
    [/quote]

    The resulting cities will be in the $city array.


    Of course, you'll have to customize it to fit in your script, and I haven't actually tested this code, so it may not work. But in either case it should give you a good idea of what it would look like.

    [This message has been edited by moderator (edited 07-27-99).]
  4. #3
  5. No Profile Picture
    DesertFox
    Guest
    Devshed Newbie (0 - 499 posts)
    I have another suggestion, but, it would depend if the cityname is on a different field.


    Then you can issue a select command like:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    select distinct cityname from table1 where ...whatever criteria.
    [/quote]

    Then again this might cause too much server overhead.

    Just a thought.
  6. #4
  7. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Actually, using 'distinct' in a query is going to cost LESS overhead then parsing the entire table thru php to get the same thing. The only time it would be advisable is if you have php and mysql on seperate machines AND you have more mysql processes running than php processes.

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. database access using thread
    By padmini in forum Visual Basic Programming
    Replies: 3
    Last Post: February 6th, 2004, 12:38 AM
  3. function within function error
    By Germanjulian in forum PHP Development
    Replies: 1
    Last Post: January 7th, 2004, 04:08 AM
  4. passing a form's select name into a javascript function
    By kilt88 in forum JavaScript Development
    Replies: 1
    Last Post: January 6th, 2004, 01:12 PM
  5. Code Benchmarking Tests
    By infamous41md in forum C Programming
    Replies: 4
    Last Post: December 27th, 2003, 04:15 PM

IMN logo majestic logo threadwatch logo seochat tools logo