So I'm building a system to make it easier to manage the auction for this event for a customer. I currently have 3 tables:
CREATE TABLE `dtco_auction_items` (
`id_item` int(11) NOT NULL auto_increment,
`donor_id` int(11) NOT NULL,
`item_name` varchar(50) NOT NULL,
`item_value` float NOT NULL,
`item_live` tinyint(1) NOT NULL,
`item_desc` text NOT NULL,
`item_rest` text NOT NULL,
`item_del` tinyint(1) NOT NULL,
`item_del_by` date NOT NULL,
`item_gc` tinyint(1) NOT NULL,
`item_db` tinyint(1) NOT NULL,
`date_added` date NOT NULL,
PRIMARY KEY (`id_item`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8
CREATE TABLE `dtco_auction_listing` (
`id_listing` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`desc` text NOT NULL,
`type` enum('sports','vacation','activity','other') NOT NULL,
PRIMARY KEY (`id_listing`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
CREATE TABLE `dtco_item_listing` (
`id_item` int(11) NOT NULL,
`id_listing` int(11) NOT NULL,
KEY `id_item` (`id_item`,`id_listing`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
I have the following query for retrieving all items that are not currently in a listing:
SELECT di . *
FROM dtco_auction_items AS di
LEFT JOIN dtco_item_listing AS il ON di.id_item = il.id_item
LEFT JOIN dtco_auction_listing AS al ON il.id_listing = al.id_listing
WHERE il.id_item IS NULL
This works exactly as desired. I have another query to retrieve all the listings and their combined value:
SELECT SUM( di.item_value ) AS Total, al . *
FROM dtco_auction_listing AS al
LEFT JOIN dtco_item_listing AS il ON il.id_listing = al.id_listing
LEFT JOIN dtco_auction_items AS di ON di.id_item = il.id_item
GROUP BY il.id_listing
What I'm looking for is a way to change the second query, such that I can build my page so that when someone clicks a little + button next to the listing, they can then see the individual items. Maybe this needs to be done with a second query run for each item but that doesn't sound right. Basically I want the output to look like this:
+-----------------------------------------------------------------+
| Listing Name | Value | Type | Description (shortened) | Items |
+--------------+-------+--------+-------------------------+-------+
| Test | 500 | Sports | Steelers Paraphanalia...| 3 [+]|
+--------------+-------+--------+-------------------------+-------+
| Test 2 | 750 |Activity| Safaria for 2 | 4 [+]|
+-----------------------------------------------------------------+
then when you click the plus I'd like to show the contained items for it as such:
+-----------------------------------------------------------------+
| Listing Name | Value | Type | Description (shortened) | Items |
+--------------+-------+--------+-------------------------+-------+
| Test | 500 | Sports | Steelers Paraphanalia...| 3 [-]|
| -> Throw Blanket - 35 | | |
| -> Autographed Jersy - 165 | | |
| -> 4 tickets to a game - 300| | |
+--------------+-------+--------+-------------------------+-------+
| Test 2 | 750 |Activity| Safaria for 2 | 4 [+]|
+-----------------------------------------------------------------+
I hope that makes sense. I'm just not sure how to go about building this output like this. I appreciate any input you might have. Sorry for the ASCII art lol
TIA