MyBB Community Forums

Full Version: $db->query fetch and call via template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi to all member and mybb team i like you forum so i decided to use it for my users.

The problem is understanding templates and php processing in this forum.

$tlimit = 5;
 
 
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
 
    $list = '';
        $bgcolor = alt_trow(true);
        $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
        $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
    while($fetch = $db->fetch_array($query))
    {
        $list .= "<tr><td class=\"{$bgcolor}\" width=\"20%\"><span class=\"smalltext\"><a href=\"showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></span></td>";
       
    }



//output data
 
$list = "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\" width=\100%\">
<thead>
<tr>
<td colspan=\"5\" class=\"thead\"><strong>Output</strong><div class=\"expcolimage\"><img src=\"{$theme['imgdir']}/collapse.gif\" id=\"list_img\" class=\"expander\" alt=\"[-]\" title=\"[-]\" /></div></td>
</tr>
</thead>
<tbody style=\"{$expdisplay}\" id=\"list_e\">
<tr>
<td class=\"tcat\" width=\200\"><span class=\"smalltext\"><strong>List data</strong></span></td>
</tr>
 
{$list}
 
</tbody>
</table>
<br />";
 

echo $list;

Making this code and puting it in index.php i was able to fetch new threads from the db and sorting them so it`s ok.

But, i dont the like the place where its generate data on index.php in the browser so i decided to cal it in template wehere i wont it to show and in html to make it litle better but i cannot find out how, so, i need your help guys in order to solve this puzzle.

Basicly i need to make file php to call query and fetch and in template to call it where i wont it to show on the forum.

Maybe something like this but.... not quite good as i see.

Index.php

$tlimit = 5;
 
 
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
 
    $list = '';
        $bgcolor = alt_trow(true);
        $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
        $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
    while($fetch = $db->fetch_array($query))
    {
        $list .= "<tr><td class=\"{$bgcolor}\" width=\"20%\"><span class=\"smalltext\"><a href=\"showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></span></td>";
       
    }

Ixdex page template/index



{$forums}
<?php   

	$list = "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\" width=\100%\">
<thead>
<tr>
<td colspan=\"5\" class=\"thead\"><strong>Letzte Themen</strong><div class=\"expcolimage\"><img src=\"{$theme['imgdir']}/collapse.gif\" id=\"list_img\" class=\"expander\" alt=\"[-]\" title=\"[-]\" /></div></td>
</tr>
</thead>
<tbody style=\"{$expdisplay}\" id=\"list_e\">
<tr>
<td class=\"tcat\" width=\200\"><span class=\"smalltext\"><strong>Nove</strong></span></td>
</tr>
 
{$list}
 
</tbody>
</table>
<br />";

	?>

{$boardstats}

And something like this not good enoff.

New php  in root / 123.php

$tlimit = 5; // How many titles you want
 
 
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."threads ORDER BY `tid` DESC LIMIT $tlimit");
 
    $list = '';
        $bgcolor = alt_trow(true);
        $lastpostdate = my_date($mybb->settings['dateformat'], $thread['lastpost']);
        $lastposttime = my_date($mybb->settings['timeformat'], $thread['lastpost']);
    while($fetch = $db->fetch_array($query))
    {
        $list .= "<tr><td class=\"{$bgcolor}\" width=\"20%\"><span class=\"smalltext\"><a href=\"showthread.php?tid={$fetch['tid']}\" target=\"_blank\">".htmlspecialchars_uni($fetch['subject'])."</a></span></td>";
       
    }


Then on template index again

{$forums}
  
<?php   

	$123 = "<table border=\"0\" cellspacing=\"{$theme['borderwidth']}\" cellpadding=\"{$theme['tablespace']}\" class=\"tborder\" width=\100%\">
<thead>
<tr>
<td colspan=\"5\" class=\"thead\"><strong>Letzte Themen</strong><div class=\"expcolimage\"><img src=\"{$theme['imgdir']}/collapse.gif\" id=\"list_img\" class=\"expander\" alt=\"[-]\" title=\"[-]\" /></div></td>
</tr>
</thead>
<tbody style=\"{$expdisplay}\" id=\"list_e\">
<tr>
<td class=\"tcat\" width=\200\"><span class=\"smalltext\"><strong>Nove</strong></span></td>
</tr>
 
{$list}
 
</tbody>
</table>
<br />";

	?>

  
{$boardstats}

Ok i fugered out. Calling like {$display_that} {$get_recent} etc.