Show database results on template page?
I'm still new to PHP and MySQL coding, especially when it comes to using it with MyBB.

What I've done is created a new php page for my website and have it pull the coding from one of the global templates to use for the page. What I want to do is then have it pull information from a database table that I've created and display it on the page.

This is the coding I have so far:


define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

$plugins->add_hook("index_start", "add_dominions", 1000000);

add_breadcrumb("Test", "test.php"); // (2)

// Build dominions table
function add_dominions()

    global $db, $mybb, $dominions;

    $domQuery = $db->query("
            SELECT *
            FROM ".TABLE_PREFIX."dominions
            WHERE discovered = '1'
            ORDER BY dominion ASC

    while($row = mysqli_fetch_array($domQuery)){

        $domid         = $row['domid'];
        $domname     = $row['dominion'];
        $description     = $row['description'];
        $power         = $row['power'];
        $control     = $row['control'];

        $dominions = $domname;



eval("\$test = \"".$templates->get("test")."\";"); // (3)
output_page($test); // (4)

When I put {$dominions} onto the template, it will only show the last result in the table, it doesn't keep the while loop going. How can I code this so it'll show all the results, rather than just the one?

Messages In This Thread
Show database results on template page? - by Silhouette - 2017-02-12, 02:57 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)