General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 15th, 2003, 02:25 PM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
Question Quering for Uniques, question

Hey all,

I have a sort of problem. I have a script that searches for airline routes based on departure and destination. The way its set is this: I have 4 steps. The first step shows a search form to search for either depature airport name or code. Then the script does some manipulating and shows the second step, this is where I have some problems. The script searches through the mysql table for all destinations associated with the selected departure, but sometimes there are multiple flights that go to the same place at different times (for example, Chicago to Detroit, there are something like 6 of them), so when the select menu comes up, it has 6 Detroits, 4 New Yorks, etc. How can I query just to pick up uniques? This way the menu will have one detroit and one new york, then at the last step I can show all of the flights that are Chicago to Detroit.

Thanks

Reply With Quote
  #2  
Old July 15th, 2003, 03:07 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
You could do something like an inline search, search what you already have saved in your combobox for the next item, if it's found then skip to the next item, and search over, otherwise add it to the list..

example pseudocode:


Quote:
1. Gather all of the results and store them in the array $results
2. Count the # of results that came back from the query and store it in the variable $entries
3. create another array and name it $newentries
4. Zero out variable $x and $y to start nested loops
5. Start loop 1 and loop through $results (use your favorite loop and counting method)
6. Start loop2 and loop through $newentries to compare all values in $newentries to the current value in $results to make sure that none exist
6. If the values exist in $newentries then exit loop2 and go back to step 5, incrimenting x to go to the next entry. Otherwise continue to step 7
7. The value does not exist in $newentries, add it and incriment x and go to step 5 and continue until x = $entries


Hope this helps

Last edited by nicat23 : July 15th, 2003 at 03:11 PM.

Reply With Quote
  #3  
Old July 15th, 2003, 03:14 PM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
yep, that helps a lot, thanks!

Reply With Quote
  #4  
Old July 15th, 2003, 03:17 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
No worries... and I forgot one more thing

Step 8. When you have all of the entries gathered, loop through and add them to a dropdown

Glad to have been able to help

Reply With Quote
  #5  
Old July 15th, 2003, 03:35 PM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
One more question. Instead of doing nested loops and multiple arrays, could I add all of the values from the query to an array, then do an array_unique() on it, and loop through it to add it to the select?

Reply With Quote
  #6  
Old July 15th, 2003, 03:38 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
possibly but I'm not very sure... Haven't tried using array_unique... let me look into it then I'll post again

Reply With Quote
  #7  
Old July 15th, 2003, 04:29 PM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
Actually, the array_unique does work, if you manipulate it a bit, I found a function on the php.net website that will do the unique strip as well as redo the keys. Here is the function and my final code:
PHP Code:
function array_unique_key($_array){
        
$tmparr array_unique($_array);
        
$i=0;
        foreach (
$tmparr as $v) { 
        
$newarr[$i] = $v;
        
$i++;
        }
        return 
$newarr;


PHP Code:
while($row mysql_fetch_array($result)){
               
$dc $row['to_loc'];
               
array_push($ds$dc);
           }
$ds array_unique_key($ds);
$r "";
foreach(
$ds as $dc){
               
$dquery "SELECT name FROM TABLE WHERE FIELD= '$dc'";
               
$dresult mysql_query($dquery) or die("Error: " mysql_error());
               
$dl mysql_fetch_array($dresult);
               
$dn $dl['name'];
               
$r .= "<option value=\"route.php?step=3&o=" $o "&d=" $dc "\">" $dn "</option>\n";


That worked fine

Last edited by PFerrara : July 15th, 2003 at 04:31 PM.

Reply With Quote
  #8  
Old July 15th, 2003, 04:32 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Sweet you taught me something new... Thanks!!

Reply With Quote
  #9  
Old July 16th, 2003, 09:59 AM
PFerrara PFerrara is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 19 PFerrara User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to PFerrara Send a message via AIM to PFerrara
Another even easier way to get back uniques is to SELECT DISTINCT in the sql query, instead of just SELECT

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Quering for Uniques, question


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT