Re: Re: Sort with PHP or SQL?
| From: | Patrick Teague | Date: | Sat, 06 Jul 2002 06:21:36 +0000 |
| Subject: | Re: Re: Sort with PHP or SQL? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-105813@lists.php.net to get a copy of this message | ||
> *ANY* time you can sort/search in SQL, or you can do it in PHP, the SQL
way
> will be faster.
< and >
> Grouping and sorting is something databases specialize in.
Any suggestions on how to do this? Currently I have a table with Headers &
another table with Pages... Should I create yet another table for
Sub-Headers? The other thing I've thought of is putting everything in 1
table, but this seems slightly daunting. Here are the SQL statements I used
to make the 2 tables I currently have -
CREATE TABLE Headers (
Header_ID INT NOT NULL AUTO_INCREMENT,
Header VARCHAR(25),
HeaderOrder INT NOT NULL,
HeaderInfo TEXT,
PRIMARY KEY(Header_ID));
CREATE TABLE Pages (
Page_ID INT NOT NULL AUTO_INCREMENT,
PageTitle VARCHAR(25),
Header_ID INT NOT NULL,
PageOrder INT NOT NULL,
PageContent TEXT,
PRIMARY KEY(Page_ID));
& then my current sql statement for php -
$query = "SELECT * " .
"FROM Headers LEFT JOIN Pages ON (Headers.Header_ID=Pages.Header_ID) " .
"ORDER BY HeaderOrder DESC, Header, PageOrder DESC, PageTitle;";
Any ideas on optimizing this? DB stuff doesn't come near the top of things
I'm good at :) The other problem is that any pages that end up having no
Header "disappear", which is a good thing on the menu, but a bad thing on
the admin pages when you're trying to connect all of them.
Patrick