MySQL
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Tutorialized ForumsDatabasesMySQL

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 Tutorialized Forums Sponsor:
  #1  
Old August 10th, 2005, 03:24 PM
jetblacknewyear jetblacknewyear is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 36 jetblacknewyear New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
a MySql SELECT question

hey. i know php pretty well, i've been working with it for a while and even built a profile/messageboard website with it, but one thing has been bothering me.

i have a "show" section where users can post shows. to make it easier, i wanted to list the cities the shows are in so if they click on the link of the city, it only displays the shows in that city. so that all worked, i just have 1 thing to fix.

how ever many shows are in that city, that's how many times the cities' link shows.

here's the link: http://www.imoptical.com/ontario/in...p?a=shows&shows

i made a loop to collect all the city names. i just don't know how to say "if this city has been posted, don't show it" in the loop, or "only select this city once" in the query.

please help. i've tried so many things and have given up. if you can help, then thank you very much

Reply With Quote
  #2  
Old August 13th, 2005, 03:32 PM
m0nkey_mafia m0nkey_mafia is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Location: UK
Posts: 3 m0nkey_mafia New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to m0nkey_mafia
im sorry i didnt really understand your question, if you could post your query, and what it is doing, and then what you want it to do it would help.

But from what ive seen, if you query cities, and then all shows in that cities, you can either use GROUP BY city_id to find out how many shows are in each city.

Or you could do SELECT DISTINCT city_id which would stop the query returning duplicate city id's.

If you are joining the shows table onto the city table, then you may be using the wrong join, left join usually works well for me in such circumstances.

As i said this is just speculation so if you could give me more details ill be glad to help!!

Reply With Quote
  #3  
Old August 15th, 2005, 01:32 PM
jetblacknewyear jetblacknewyear is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 36 jetblacknewyear New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
basically this is what is going on:

i have a bunch of shows that are happening in ontario. so naturally, a lot of shows ahve different cities. now, there are over 100 shows stored in the DB. it'd be hard to look through all those shows when viewing the website, so i wanted to make it easier. i wanted links for each city. so if i click "Hamilton", all the hamilton shows pop up instead of seeing every show from various cities.

the onyl problem was: i wanted the links to be dynamic, because of course, i cannot list every city in my area code, so i wanted to take the city name and list it, but i couldn't figure out how to list the city and not have the same name pop up again.

if my code was:

Code:
    
$result = mysql_query("SELECT cityID FROM shows ORDER BY city ASC");
while ($r = mysql_fetch_array($result))
{
  $city = $r['cityID'];
  echo"$city
";
}


it would list every city in the database. i wanted to say: "if the city has already been listed, ignore it and move on"

so after days of messing around with stuff that just got me frustrated, i finally came up with this.

Code:
    
$result = mysql_query("SELECT cityID FROM shows ORDER BY city ASC");
while ($r = mysql_fetch_array($result))
{
  $city = $r['cityID'];
  if ($city != $found[$cityID]){
    echo"$city
";
  }
  $found[$cityID] = $city;
}


what this does is it makes a list for example like:
$found[hamilton];
$found[toronto];
$found[ottawa];
$found[barrie];

so if the city comes up again while it's printing out names, it ignores it.

is there an even easier way around this?

Reply With Quote
  #4  
Old August 15th, 2005, 01:39 PM
jetblacknewyear jetblacknewyear is offline
Contributing User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 36 jetblacknewyear New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: < 1 sec
Reputation Power: 0
i tried the SELECT DISTINCT and the GROUP BY and they both worked nicely. thanks. the word GROUP could have saved me days figuring this out. thanks a lot.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesMySQL > a MySql SELECT 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 6 hosted by Hostway
Stay green...Green IT