|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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).] |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Repeat Entry chop function? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|