Print This Page


sql_multipage ()

function sql_multipage ($table, $columns, $where, $order_by, $cur_page,
$script_name = '', $per_page = '')

This function will create a multiple page output from an SQL query. This is useful if the expected SQL result will be too long to fit a page. This is almost the same with MYSQL's LIMIT, only easier, and the output has been paginated.

$table = table name.

$columns = selected columns.

$where = MySQL WHERE conditions.

$order_by = MySQL ORDER BY.

$cur_page = current page.

$script_name = no longer used, kept for compatibility with older qE scripts.

$per_page = number of items per page, the default is defined in ACP > Configuration (usually 20).

Calling this function will return an array of $columns from the $table. You can later use foreach () function to display the results. Also this function will populate $txt['pagination'] with page list, based on skins/default/pagination.tpl & skins/_admin/pagination.tpl depending on current mode.

Example 1. test.php

require './includes/user_init.php';

// now load the output tpl
$tpl = load_tpl ('test.tpl');

// all block output must be contained in $var['block_list']
// or any block_name defined
$txt['block_list'] = '';

// get entries from db
$p = get_param ('p');
$foo = sql_multipage ($db_prefix.'user', '*', '', 'user_id', $p);
foreach ($foo as $row)
    // convert the date from SQL format to human format
    $row['user_since'] = convert_date ($row['user_since']);
    // create the block
    $txt['block_list'] .= quick_tpl ($tpl_block['list'], $row);

// output
$txt['main_body'] = quick_tpl ($tpl, $txt);
flush_tpl ();


<h1>Welcome to test page!</h1>
<!-- BEGINIF $login -->
<p>You are logged in as: {$current_user_id}</p>
<!-- ELSE -->
<p>You are not logged in.</p>
<!-- ENDIF -->

<table class="table_2" border="0">
        <th>User ID</th>
    <!-- BEGINBLOCK list -->
    <!-- ENDBLOCK -->

The sample code will display list of registered users. If the users more than 20, it will display page list, with a link to other pages.

Posted On: Aug-23-2010 @ 07:00am
Last Updated: Jan-01-1970 @ 07:00am

There is no comment. Why not be the first?

More Comments/Post Your Own

Powered by qEngine
Generated in 0.011 second | 15 queries