Forums

How to redirect form?

goliath 19 May, 2015
I tried to redirect my form to a specified url when the sum of the column 'aantal' of all records reaches a certain amount (e.g. 15).

I tried to put this code in a custom code action in the 'On load' action but this doesn't work:

<?php
$db =& JFactory::getDBO();
$query = "
    SELECT *
        FROM `#__my_table` ;
";
$db->setQuery($query);
$aantal = mysql_fetch_array(mysql_query("SELECT SUM(aantal) FROM #__my_table"));
if ( $aantal >= 15 ) {
  // Redirect to my url
  $app =& JFactory::getApplication();
  $app->redirect('myurl');
}
?>
GreyHead 19 May, 2015
Answer
Hi geertmartens,

Please try
<?php
$db = JFactory::getDBO();
$query = "
  SELECT SUM(`aantal`)
    FROM `#__my_table` ;
";
$db->setQuery($query);
$aantal = $db->loadResult();
if ( $aantal >= 15 ) {
  // Redirect to my url
  $app = JFactory::getApplication();
  $app->redirect('myurl');
}
?>

Bob
goliath 19 May, 2015
Works like a charm!
Thanks Bob!
This topic is locked and no more replies can be posted.