Go to Post Learn the subjects that interest you, but at the same time know how it relate to real life situations, and how it is applied. - Ryan Dognaux [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-02-2003, 14:23
Jack's Avatar
Jack Jack is offline
FIRST Scouting Network
AKA: Andrew Schenk
FRC #0201 (The FEDS)
Team Role: Alumni
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Rochester Hills
Posts: 643
Jack is a jewel in the roughJack is a jewel in the roughJack is a jewel in the rough
Send a message via AIM to Jack
MySQL query question

ok... I have a little problem.

I want to run a select query. Example:

SELECT DISTICT topic_id
FROM posts
ORDER BY topic_time DESC

now, as expected, the order by doesn' t do anything. (except making the topic id go descending)

but... if i go

SELECT DISTINCT topic_id, topic_time
FROM posts
ORDER BY topic_time DESC

I get the correct sort order, but now i have more than one rows for each topic_id (becuase the topic_time for the topic_id s are different)

So... If you don't get what I said above, I'll try to now explain in just english.

I want to select unique topic_id. However, i want to order them by topic_time. The topic_time for each topic_id is different.

Can anyone help?
__________________
Team 201 - 2003 Great Lakes Semifinalists & 2003 Archimedes Division Finalists :|: Webmaster of www.feds201.com -> FBI Scouting
Winner of The 2003 ChiefDelphi Web Award for: User That Started The Most Non Chit Chat Threads
Winner of: 2003 FIRST Ventures with 5451.68 End Points

All about me: http://knehcsa.vze.com
**Check out the New FIRST Scouting Network**
  #2   Spotlight this post!  
Unread 01-02-2003, 14:51
Duke 13370's Avatar
Duke 13370 Duke 13370 is offline
C is for cookie...
#0862 (Team Lightning)
Team Role: Webmaster
 
Join Date: Jan 2003
Location: Plymouth, MI
Posts: 215
Duke 13370 will become famous soon enough
Send a message via AIM to Duke 13370
You have to include the variable you will sort by to use it.

Otherwise strange things may occur
__________________
---Lightning Robotics!---
  #3   Spotlight this post!  
Unread 01-02-2003, 15:53
Jeremy_Mc's Avatar
Jeremy_Mc Jeremy_Mc is offline
GitHubber
no team
Team Role: Mentor
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Orlando, FL
Posts: 496
Jeremy_Mc will become famous soon enoughJeremy_Mc will become famous soon enough
if you're just trying to get a specific one, why not use WHERE?

or is that not what you're doing (i've never seen 'DISTINCT')?


*jeremy
__________________
GitHub - Collaborate on code, documentation, etc. - http://github.com
  #4   Spotlight this post!  
Unread 01-02-2003, 15:59
AJ Quick's Avatar
AJ Quick AJ Quick is offline
Your Attention Please
FRC #0006 (CogSquad)
Team Role: Alumni
 
Join Date: Oct 2002
Rookie Year: 2001
Location: Minnesota
Posts: 464
AJ Quick has a spectacular aura aboutAJ Quick has a spectacular aura about
Sounds like a phpBB type of script.. what are you trying to achieve?

PM me if you need some specific help.
__________________
-AJ Quick (Alum on Team 6)
http://www.HHSRobotics.com/

Place your attention entirely on my voice and try to ignore all the others. It is important to be able to focus on a single source of information while blocking out all the other things competing for your attention.
  #5   Spotlight this post!  
Unread 01-02-2003, 17:53
Jack's Avatar
Jack Jack is offline
FIRST Scouting Network
AKA: Andrew Schenk
FRC #0201 (The FEDS)
Team Role: Alumni
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Rochester Hills
Posts: 643
Jack is a jewel in the roughJack is a jewel in the roughJack is a jewel in the rough
Send a message via AIM to Jack
ya, it's phpBB... but is really just because i'm not that great as SQL.

anyways...

a[100, 101, 102, 103, 104] b[3, 8, 3, 1, 8]

the a&b are the fields and 100 -> 3 ; 101 -> 8 ; ... ; 104 -> 8

(that's my best way of making a table)

now, for the output, I want: 1, 3, 8

yet, I want them in the order of 8, 1, 3

as you can see, I want the numbers sorted by the 'a' field DESC but I don't want repeats in the b field.

actually what i'm trying to do is (you better know the phpBB table layout) is select the topic_id from phpbb_posts sorted by post_time with unique (no repeats) of the topic_id.

can anyone help?

PS: DISTINCT, DISTINCT ROW whatevery you like.
__________________
Team 201 - 2003 Great Lakes Semifinalists & 2003 Archimedes Division Finalists :|: Webmaster of www.feds201.com -> FBI Scouting
Winner of The 2003 ChiefDelphi Web Award for: User That Started The Most Non Chit Chat Threads
Winner of: 2003 FIRST Ventures with 5451.68 End Points

All about me: http://knehcsa.vze.com
**Check out the New FIRST Scouting Network**
  #6   Spotlight this post!  
Unread 01-02-2003, 19:37
Jeremy_Mc's Avatar
Jeremy_Mc Jeremy_Mc is offline
GitHubber
no team
Team Role: Mentor
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Orlando, FL
Posts: 496
Jeremy_Mc will become famous soon enoughJeremy_Mc will become famous soon enough
are you trying to get the most recent posts?

if so, look on www.firstubergeeks.com/downloads.php we have a script for that on there...it's sloppy and uncommented, but if you want to download it i can fix that. just pm me before you do

*jeremy
__________________
GitHub - Collaborate on code, documentation, etc. - http://github.com
  #7   Spotlight this post!  
Unread 01-02-2003, 19:52
Jack's Avatar
Jack Jack is offline
FIRST Scouting Network
AKA: Andrew Schenk
FRC #0201 (The FEDS)
Team Role: Alumni
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Rochester Hills
Posts: 643
Jack is a jewel in the roughJack is a jewel in the roughJack is a jewel in the rough
Send a message via AIM to Jack
Jeremy_Mc - that's almost what i want. However, the topics repeat. (Ex: if the past two posts were in the same topic, then that topic shows up twice) Is there anything you could do to not have that happen.

I've been playing with my sql statement for a while now, and can't figure it out.
__________________
Team 201 - 2003 Great Lakes Semifinalists & 2003 Archimedes Division Finalists :|: Webmaster of www.feds201.com -> FBI Scouting
Winner of The 2003 ChiefDelphi Web Award for: User That Started The Most Non Chit Chat Threads
Winner of: 2003 FIRST Ventures with 5451.68 End Points

All about me: http://knehcsa.vze.com
**Check out the New FIRST Scouting Network**
  #8   Spotlight this post!  
Unread 01-02-2003, 20:12
Jeremy_Mc's Avatar
Jeremy_Mc Jeremy_Mc is offline
GitHubber
no team
Team Role: Mentor
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Orlando, FL
Posts: 496
Jeremy_Mc will become famous soon enoughJeremy_Mc will become famous soon enough
Our script just does this when that happens:

The Post - by theirname
The Post [response name] - by theirname


I could edit to only show up once tho if needed.

*jeremy
__________________
GitHub - Collaborate on code, documentation, etc. - http://github.com
  #9   Spotlight this post!  
Unread 01-02-2003, 22:33
AJ Quick's Avatar
AJ Quick AJ Quick is offline
Your Attention Please
FRC #0006 (CogSquad)
Team Role: Alumni
 
Join Date: Oct 2002
Rookie Year: 2001
Location: Minnesota
Posts: 464
AJ Quick has a spectacular aura aboutAJ Quick has a spectacular aura about
I don't know how good this info is, but you can order by 2 things at the same time. You can order by the topic_time, then order by the topic_id. Such is:

PHP Code:
ORDER BY topic_timetopic_id 
What it sounds like you really want is the group function of mySQL. With that you can group those of the same value together. So:

PHP Code:
GROUP BY topic_id 
Would give you the topic_ids all together, then you can sort by topic time.. so try this out for size:

PHP Code:
SELECT topic_id FROM posts GROUP BY topic_id ORDER BY topic_time DESC 
That should do everything. But you are going to want to look out for private forums, and other things you don't want it to catch. That should put you out where you need to be.. but I think you should also check out http://www.phpbbhacks.com/ for these types of things. (There is a most recent topics on any page type of code on there).
__________________
-AJ Quick (Alum on Team 6)
http://www.HHSRobotics.com/

Place your attention entirely on my voice and try to ignore all the others. It is important to be able to focus on a single source of information while blocking out all the other things competing for your attention.
  #10   Spotlight this post!  
Unread 02-02-2003, 00:11
Jack's Avatar
Jack Jack is offline
FIRST Scouting Network
AKA: Andrew Schenk
FRC #0201 (The FEDS)
Team Role: Alumni
 
Join Date: Feb 2002
Rookie Year: 2002
Location: Rochester Hills
Posts: 643
Jack is a jewel in the roughJack is a jewel in the roughJack is a jewel in the rough
Send a message via AIM to Jack
ok, to end the SQL saga here is what i got:

PHP Code:
SELECT t.topic_idt.topic_title 
        FROM phpbb_topics 
AS tphpbb_forums AS fphpbb_posts AS 
        WHERE p
.post_id t.topic_last_post_id AND t.forum_id f.forum_id AND f.auth_read 
        ORDER BY p
.post_time DESC 
        LIMIT 0
,15 
I would like to give many thanks to Brandon for reminding me that there is a field called topic_last_post_id (he really is the god of php/sql/web stuff ) oh, and thanks to everyone else who helped.

jack
__________________
Team 201 - 2003 Great Lakes Semifinalists & 2003 Archimedes Division Finalists :|: Webmaster of www.feds201.com -> FBI Scouting
Winner of The 2003 ChiefDelphi Web Award for: User That Started The Most Non Chit Chat Threads
Winner of: 2003 FIRST Ventures with 5451.68 End Points

All about me: http://knehcsa.vze.com
**Check out the New FIRST Scouting Network**

Last edited by Jack : 02-02-2003 at 00:17.
Closed Thread


Thread Tools
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Message Boards w/o MySQL iBob Website Design/Showcase 7 13-07-2003 02:00
my idea of a question forum... Ken Leung General Forum 12 30-11-2002 12:17
MnM EASY Question of the Day Winners! Mike Bonham General Forum 22 03-05-2002 21:21
Chief Delphi Site Question Mike Bonham General Forum 1 16-02-2002 22:18
Rookie Programmer has question about the default code DanL Programming 3 26-01-2002 19:59


All times are GMT -5. The time now is 02:03.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi