COMPANY 1
item - item size - item version
item - item size - item version
item - item size - item version
COMPANY 2
item - item size - item version
item - item size - item version
item - item size - item version
But I would like it to output like this:
COMPANY 1
item size one
item - item version
item - item version
item - item version
item size two
item - item version
item - item version
item - item version
etc
COMPANY 2
item size one
item - item version
item - item version
item - item version
item size two
item - item version
item - item version
item - item version
etc
Change the query to sort it by company then item size then item/item version, loop through the results and echo them, noting each time the company or item size changes so you can display the new heading / title.
Thank you for your reply. I have changed the query to order by company->size->item etc. The part that is hard for me to understand how to achieve (I am a php novice) is then sorting via size under each company.
Sorting all items via company was pretty easy to get going… but to sort for something under something else… would I just add to my current code, or would I completely need to re-write/re-do the way I have written it?
Well, as long as the query specifies all the orders in the correct sequence, they should all come out. I don’t know your table or column names but something like
select * from items order by company, item_size, item, item_version
Then in your code:
$lastcomp = "";
while ($row = $sql->fetch()) {
if ($row['company'] != $lastcomp) {
// display the company name
echo "company name";
$lastsize = ""; // clear this here so it's always shown on a new company
}
if ($row['item_size'] != $lastsize) {
//display the item size
echo "item size";
}
// display the item and item version from the row
echo "whatever...";
$lastcomp = $row['company'];
$lastsize = $row['item_size'];
} // end of while() loop
So the loop will remember the company and item size from the previous record, and when the current record is different you can display that information.