Results 1 to 4 of 4
March 24th, 2005, 07:56 AM #1Grouping with PHP and MySQL
Does anyone know how to have Records grouped??
Select * from tbl_shoes group by fld_color;
The output should be something like:
And So on
March 24th, 2005, 08:53 AM #2
I'm no PHP expert yet but this one looks easy enough...
Assuming you have a shoe-color column, this should work:
SELECT * from table_name ORDER BY column_name
(That's the straight MySQL query. [Now I know why people say, "it depends on what you want to do!" IF you want to have it so the user affects the page's output by selecting something, you'll need to pass the user's selection into the code with a variable. But IF you just want the page to do the same thing every time, for instance for a site's main index, then this query should do ya... and there's probably a few other "ifs" I'm forgetting about!])
It wouldn't put those headers you showed in, though, if they don't exist in your table. You'd get something like:
etc. etc.There is no knowledge that is not power. ~Hemingway
March 24th, 2005, 08:54 AM #3
While you're in a loop fetching the rows from the query, check to see if the current color is different from the last color (keep a "last color" variable) and print a heading.
consultant by day, affiliate by night
March 24th, 2005, 09:07 AM #4
[QUOTE=infospongellc]While you're in a loop fetching the rows from the query, check to see if the current color is different from the last color (keep a "last color" variable) and print a heading.
Any chance at getting an example of what that script would look like??
By scm21st in forum Midnight Cafe'Replies: 5Last Post: August 5th, 2007, 09:30 PM
By spiderninja in forum Midnight Cafe'Replies: 0Last Post: January 31st, 2007, 10:12 PM
By AddHandler in forum Programming / Datafeeds / ToolsReplies: 13Last Post: May 7th, 2005, 02:25 PM
By perfectG in forum Programming / Datafeeds / ToolsReplies: 1Last Post: November 6th, 2002, 05:58 AM