PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 27th, 1999, 02:16 AM
newmediaarts
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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

Reply With Quote
  #2  
Old July 27th, 1999, 02:28 PM
moderator
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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).]

Reply With Quote
  #3  
Old July 28th, 1999, 08:06 PM
DesertFox
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.

Reply With Quote
  #4  
Old July 29th, 1999, 06:59 AM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Repeat Entry chop function?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap