I am trying to learn a little by simply making the following:
A page that will query the database for all smilies. It will display 3 smilies per row and 5 rows per page.
Now, I checked the documentation and found a great code-snippet to query the DB, but I still can't figure out how to make it stop at 5 rows.
Code: Select all
<?php
// standard hack prevent
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
// standard session management
$userdata = session_pagestart($user_ip, PAGE_klaus);
init_userprefs($userdata);
// set page title
$page_title = 'klaus';
$columns_per_row = 3; // or whatever you want
// create and execute our database query....
$sql = "SELECT * FROM phpbb_smilies";
if ( !($result = $db->sql_query($sql)))
{
message_die(GENERAL_ERROR, "Could not query user table.", '', __LINE__, __FILE__, $sql);
}
// now here comes the interesting stuff
$i = 0;
while ( $row = $db->sql_fetchrow($result) )
{ if ($row == 5) { exit; }
if ( !($i % $columns_per_row) ) // modulus kicks butt
{
$template->assign_block_vars('row',array());
}
$template->assign_block_vars('row.cell', array('CONTENT' => $row['smile_url']));
$i++;
}
// standard page header
include($phpbb_root_path . 'includes/page_header.'.$phpEx);
// assign template
$template->set_filenames(array(
'body' => 'klaus.tpl')
);
$template->pparse('body');
// standard page footer
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>
Code: Select all
while ( $row = $db->sql_fetchrow($result) )
{ if ($row == 5) { exit; }
if ( !($i % $columns_per_row) ) // modulus kicks butt
{
$template->assign_block_vars('row',array());
}
$template->assign_block_vars('row.cell', array('CONTENT' => $row['smile_url']));
$i++;
if ($i > 14) { exit ; }
}
Here's what I use in the tpl file to display the smilies:
Code: Select all
<center>
<!-- BEGIN row -->
<table width="500">
<tr>
<!-- BEGIN cell -->
<td align="center" width="80"><img src="images/smiles/{row.cell.CONTENT}" /></td>
<!-- END cell -->
</tr>
</table>
<!-- END row -->
</center>
I really appreciate any kind of help you can give me.
Thanks in advance.