TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-29-2009, 01:34 PM   #1 (permalink)
jon
The Visitor
 
jon's Avatar
 
Join Date: May 2005
Posts: 4
Thanks: 0
jon is on a distinguished road
Default Probably a very easy mysql question.

I'm working on a hilariously simple forum script. Right now to grab all of the thread information I'm doing the following query.

PHP Code:
$sql "select thread.ID, title, thread, thread.date, views, name, avatar from thread, users where userid=users.ID  order by thread.date DESC;"
That works fine but I'd like to order the threads not by the date that they were created but by the latest comment made in them.

I have another table called "comments". Here is my table structure.



thread.ID in the "thread" table and threadid in the "comments" table match up.

How do I alter my original query so that I can order by comments.date? I've messed about and tried everything I can think of but it always fails.

Incidentally you can view the live fail forum here.
__________________
yesthat.com
jon is offline  
Reply With Quote
Old 01-29-2009, 02:48 PM   #2 (permalink)
jon
The Visitor
 
jon's Avatar
 
Join Date: May 2005
Posts: 4
Thanks: 0
jon is on a distinguished road
Default

I managed to solve the problem. Rather than trying to do some out-of-my-depth mysql query I added another column to "thread" called "lastupdate". Then each time a new comment was made inserted the current timestamp into the thread table as well as the date column on the comments table.

Now it's working like a charm.
__________________
yesthat.com
jon is offline  
Reply With Quote
Old 01-29-2009, 07:51 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I'm glad you sorted it. Although when you have queries of this nature that are quite intensive, you should take a look at using MySQL views. I realise it's supposed to be a simple forum package, however, views will add to the efficiency of such queries.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 01-30-2009, 01:53 AM   #4 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

Look into joins as well. Thats all that is needed to solve the problem without changing the db.
CoryMathews is offline  
Reply With Quote
Old 02-18-2009, 06:20 AM   #5 (permalink)
dp2
The Visitor
 
Join Date: Feb 2009
Posts: 4
Thanks: 0
dp2 is on a distinguished road
Default

Your table structure graphic are they easy to create?

How do you generate these diagrams of your database tables

Is this done in shell access and print screen and copy and paste into photoshhop or is this a spreadsheet graphic.

What is the name of these text boxes
dp2 is offline  
Reply With Quote
Old 02-26-2009, 03:15 AM   #6 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

Quote:
Originally Posted by dp2 View Post
Your table structure graphic are they easy to create?

How do you generate these diagrams of your database tables

Is this done in shell access and print screen and copy and paste into photoshhop or is this a spreadsheet graphic.

What is the name of these text boxes
Since he didn't answer you, I am assuming they are just screenshots....
allworknoplay is offline  
Reply With Quote
Old 02-26-2009, 08:26 PM   #7 (permalink)
dp2
The Visitor
 
Join Date: Feb 2009
Posts: 4
Thanks: 0
dp2 is on a distinguished road
Default

I assume the screen shots are created through the shell access
dp2 is offline  
Reply With Quote
Old 02-26-2009, 11:11 PM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Yes, those ones are. I am not sure what the name of these tables are. Perhaps ASCII Tables? ASCII Tabular Data?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a MySQL class Andrew General 12 07-14-2009 03:49 PM
Securing your MySQL Queries with Sprintf Wildhoney General 26 03-18-2008 06:52 PM
MySQL Sell Up Alan @ CIT The Lounge 12 01-17-2008 05:46 PM
Error in connecting to MySQL via PHP EyeDentify MySQL & Databases 0 01-03-2008 01:06 PM
Notepage like application to open large MySQL files Wildhoney General 6 12-07-2007 02:18 PM


All times are GMT. The time now is 06:23 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design