• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Basic Query to Page


Active member
So I've been trying to follow the example here: http://xenforo.com/community/threads/quick-easy-dirty-pages-with-sql-database-query-results.62865/

My file is in Library/TwitchStream/test.php which contains


class TwitchStream_test
    public static function testQuery(XenForo_ControllerPublic_Abstract $controller, XenForo_ControllerResponse_Abstract &$response)
$mydb = XenForo_Application::get('db');
$testQuery = $mydb->fetchAll("
SELECT 'field_value'
FROM `xf_user_field_value`
WHERE `field_id` = 747769746368");

        $response->params['testQuery'] = $testQuery;
My page contains this in the HTML
<xen:foreach loop="$testQuery" value="$testQuery">
<br />
And php callback is TwitchStream::testQuery

There is 1 entry currently there and through phpmyadmin the query works. But when I goto the page, I get nothing. Ideas?


Well-known member
Your foreach conditional is not correct. Try this instead:

<xen:foreach loop="$testQuery" value="$test">
<br />

Chris D

XenForo developer
Staff member
In your template, try {xen:helper dump, $testQuery}

That should dump the contents (if any) of the $testQuery param.


Active member
So it looks like it was a simple punctuation, works in mysql but not in xenforo. So got that working but now got another question.

I'm in a nutshell, I'm trying to grab a Profile field from xenforo(which I do above), take each users profile field and loop it through another websites API, grab data from that and use it on a page on Xenforo. So to reduce load on the server I figured i'd schedule it to update every couple of minutes. Without knowing how Xen's Cron functions work Should I

  1. Create a normal php file, have the webserver's cron management handle the data, upload it to a new table in MYSQL and then try to pull that data from xenforo.
  2. Use Xenforo's cron management to archieve the data and then pull it back in when needed.
  3. Maybe a better way to handle it?