Hi. I need to connect my form to the db table based on selection and login user but not sure how to fulfill it. This will go to the CSSV. I wanted to get the sum of a column based on login user and selected drop down category. My table consist of category, login user, project_cost, donate_amount. With the login user,
I have a code here but somehow it doesn't connect to db. Please help. Thanks.
if the user's category selected in the form does exist in the database table
get the total amount of donate_amount based on category and user from the table then
check if total donate_amount is equal to the total project_cost
if total donate_amount is => project_cost
allow user to continue
else
do not allow to continue
show error message
I have a code here but somehow it doesn't connect to db. Please help. Thanks.
$user=& JFactory::getUser();
$name=$user->name;
$donate =& JFactory::getDBO();
$query = "
SELECT `principal_name`, SUM(`donate_amount`) as subtotal, `category_code`
FROM `#_chronoforms_creditcard`
WHERE `principal_name` = '{$principal_name}' && `category_code`
GROUP BY `principal_name`, `category_code`
";
$donate->setQuery($query);
$info = $donate->loadObjectList();
if (empty($info)) {
$a->subtotal = "0.00";
echo '<div class="formfield">Current Total Donation Amount for Principal '.$name.' you selected is <b><u>$0.00</u></b></div>';
echo '<input type="text" id="hidden_sum" name="hidden_sum" value="'.$a->subtotal.'" />';
} else {
foreach($info as $a) {
echo '<table><tr><th>User Name</th><th>Category Code</th><th>Total</th></tr><tr><td>';
echo $a->name;
echo '</td><td>';
echo $a->category_code;
echo '</td><td>';
echo $a->subtotal;
echo '</tr></table>';
}
}