• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Can I do multiple queries?

madpad

Member
I am running into errors on this code, not sure what is missing here.

$dbcon = JFactory::getDbo();
$foodscores = $data['daily_logs_2___food_score'];
$mydata = $data['daily_logs_2___user_raw'];
$query = $dbcon->getQuery(true);
$query
->select('AVG(food_score) AS myavg_foodscore')
->from('daily_logs_2')
->where('user = '. $dbcon->quote($mydata));
$dbcon->setquery($query);
$myavg_foodscore = $dbcon->loadResult();

Can I run a second query right after the last line?

$query
->select('AVG(food_score) AS avg_foodscore')
->from('daily_logs_2')
$dbcon->setquery($query);
$avg_foodscore = $dbcon->loadResult();

Thank you for your assistance.
 
Hi, cannot see any obvious errors in your code.

Try dumping your variables and see if you get what you expect:
var_dump($foodscores);
exit;

And yes, you can run multiple queries one after another.
 
Try this:
PHP:
$dbcon = JFactory::getDbo();
$foodscores = $data['daily_logs_2___food_score'];
$mydata = $data['daily_logs_2___user_raw'];
$query = $dbcon->getQuery(true);
$query
->select('AVG(food_score) AS myavg_foodscore')
->from('daily_logs_2')
->where('user = '. $dbcon->quote($mydata));
$dbcon->setquery($query);
$myavg_foodscore = $dbcon->loadResult();

$query = $dbcon->getQuery(true);
$query
->select('AVG(food_score) AS avg_foodscore')
->from('daily_logs_2')
$dbcon->setquery($query);
$avg_foodscore = $dbcon->loadResult();
 
If I block out the second query, then there is no error. Otherwise, I continue to get an error -
Here is what I ran..
$dbcon = JFactory::getDbo();
$foodscores = $data['daily_logs_2___food_score'];
$mydata = $data['daily_logs_2___user_raw'];
$query = $dbcon->getQuery(true);
$query
->select('AVG(food_score) AS myavg_foodscore')
->from('daily_logs_2')
->where('user = '. $dbcon->quote($mydata));
$dbcon->setquery($query);
$myavg_foodscore = $dbcon->loadResult();

//$query = $dbcon->getQuery(true);
//$query
//->select('AVG(food_score) AS avg_foodscore')
//->from('daily_logs_2')
//$dbcon->setquery($query);
//$avg_foodscore = $dbcon->loadResult();

If I remove the // from the above lines, then I get the error. With the next query blocked, it runs ok.
 
Syntax error: in the second query there's a semicolon missing at the end of the line
Code:
->from('daily_logs_2')
Thank you! That works.

The list displays ok. However, the form shows an error - "1054 Unknown column 'Array' in 'where clause'"
 
Last edited:
However, the form shows an error - "1054 Unknown column 'Array' in 'where clause'"
You didn't say where/how you're using the code here above, so it's hard to say if it could be the cause... though likely not if the list is fine.
So, since it may be caused by your code here above, or not but then by something else, like DBjoin, form plugin or so: use max error display, debug (to see the queries), eventually disable things one by one to find the culprit.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top