0

I made this querry that counts all the statuses "1" for a certain ID and their summarizes add in the column "result" and it works great:

$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from($db->quoteName('#__climbing'));
$query->where($db->quoteName('#__climbing.status')." = ".$db->quote(1)." AND ".$db->quoteName('#__climbing.link_id')." = " .$db->quote($link_id));
$db->setQuery($query);
$score = $db->loadResult();
$result = "UPDATE #__mt_links SET result =". $score." WHERE link_id=".$link_id ;
$db->setQuery( $result );
$db->query();

Now I want to add the same result into another column. I added another querry, but it does not work and still executing only one:

$query = $db->getQuery(true);
$query->select('COUNT(*)');
$query->from($db->quoteName('#__climbing'));
$query->where($db->quoteName('#__climbing.status')." = ".$db->quote(1)." AND ".$db->quoteName('#__climbing.link_id')." = " .$db->quote($link_id));
$db->setQuery($query);
$score = $db->loadResult();
$result = "UPDATE #__mt_links SET price =". $score." WHERE link_id=".$link_id ;
$result2 = "UPDATE #__hikers SET score =". $score." WHERE link_id=".$link_id ;
$db->setQuery( $result );
$db->setQuery( $result2 );
$db->query();

Where did I make a mistake?

2

try

$result = "UPDATE #__mt_links SET price =". $score." WHERE link_id=".$link_id ;
$result2 = "UPDATE #__hikers SET score =". $score." WHERE link_id=".$link_id ;
$db->setQuery( $result );
$db->execute();
$db->setQuery( $result2 );
$db->execute();
  • 1
    (Remember to mark it as the correct answer otherwise the site will bump it as an unanswered question on occasion) – Drew G Feb 2 '18 at 14:45
  • 2
    Note that you should replace $db->query(); with $db->execute(); – Lodder Feb 2 '18 at 16:49
  • Good catch, Lodder. – Drew G Feb 2 '18 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.