Hi Kwok,
You can do this using ChronoForms.
I'd use a Custom Code action on the form ON Load event to get the list of images using a MySQL query with a JOIN
Then use a Custom Code element in the Preview tab to generate a table from the results.
Then two DB Save actions in the form On Submit event to save to the two tables. After the first one ChronoForms adds the new id to the form data so you can use that for the second DB Save.
Bob
Hi Bob,
1. I created custom code (buyer_items) in Designer layout session as follows:
<? php
// get buyer user id
$user = JFactory::getUser();
// get buyer's items
$db = JFactory::getDBO();
$query =
"SELECT b.path, b.name, b.ext, a.intro_desc, a.id ".
"FROM #__items a ".
"LEFT JOIN #__item_images b ON a.id=b.item_id ".
"WHERE a.user_id=".$user->id;
$db->setQuery($query);
$items = $db->loadObjectList();
?>
<table>
<thead>
<tr><th>ITEM</th><th>DESCRIPTION</th><th>IMAGE</th><th>SELECT</th>
</thead>
<tbody>
<?php
foreach ($items as $row) {
echo "<tr><td>{$row['item_id']}</td><td>{$row['intro_desc']}</td><td>{$row['name']}</td><td><input type=\"checkbox\" name=\"checkbox\" value=\"\" id=\"checkbox\"></td></tr>";
}
?>
</tbody>
</table>
But got the following during testing:
d; $db->setQuery($query); $items = $db->loadObjectList(); ?>
Notice: Undefined variable: items in C:\xampp\htdocs\xxx\administrator\components\com_chronoforms5\chronoforms\actions\html\html.php(262) : eval()'d code on line 22
Even the above works to display the table, I actually need the name row to display the item image (path/name.ext) which I have no idea how. In addition, I'm lost how to check which checkbox is selected and eventually save to the header and detail files:
CREATE TABLE IF NOT EXISTS `offer_header` (
`id` int(11) NOT NULL auto_increment,
`buyer_user_id` int(11) NOT NULL,
`date_offer` timestamp NOT NULL default CURRENT_TIMESTAMP,
`seller_item_id` int(11) NOT NULL,
`seller_item_intro_desc` text,
`seller_user_id` int(11) NOT NULL,
`offer_status` char(1) NOT NULL default '0',
`seller_date_action` timestamp NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8
CREATE TABLE IF NOT EXISTS `offer_detail` (
`id` int(11) NOT NULL auto_increment,
`offer_id` int(11) NOT NULL,
`buyer_item_id` int(11) NOT NULL,
`buyer_item_intro_desc` text,
`buyer_item_image text,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8
Would it be possible for you to show me step by step on how to set the chloroform?
Many thanks!
Kwok