I have a text size selector on my board that saves the user's selection in the DB. In the database is a tiny unsigned INT with a default of '12" in the "phpbb_users" section:
- Code: Select All
`user_view_text_size` tinyint(1) unsigned NOT NULL DEFAULT '12',
So now, please take a look at this code (the DB writing part - highlighted in red) and please tell me if I did it correctly. It works, but is it right and did I leave out any steps?
- Code: Select All
function text_size()
{
global $db, $user, $template;
$name = 'pxsize'; // select name
$fs = request_var($name, 0, false, false); // check for a user selection
if ($fs) // if user selection, write it to the db
{
$sql_ary = array( 'user_view_text_size' => $fs );
$sql = 'UPDATE ' . USERS_TABLE . '
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
WHERE user_id = ' . $user->data['user_id'];
$db->sql_query($sql);
}
else // no user selection, use current value
{
$fs = $user->data['user_view_text_size'];
}
$s_view_text_size = '<select name="' . $name . '">'; // generate the select dropdown
for ($i = 8; $i <= 24; $i++)
{
$s_view_text_size .= '<option value="' . $i . '"';
$s_view_text_size .= ($i == $fs) ? ' selected="selected"' : '';
$s_view_text_size .= '>' . $i . '</option>';
}
$s_view_text_size .= '</select>';
$template->assign_vars(array( 'S_VIEW_TEXT_SIZE' => $s_view_text_size )); // return it to the template
return $fs; // return size value to set the board body fontsize
}
Thanks!
-- Roger









