Pagination function
<p>I'm trying to make a pagination script made by Jonathan Sampson (gotta give credit for his excellent video tutorials) into a function, so that I don't have to have to write it on every page I want pagination on, so I can use it all over my site without having pagination code on every page :)</p>

<p>I thought I'd pass the query with the function and it works good:</p>

<pre><code>function pagination_query($query, $table = false, $column = false)
{

// Create some variables
$pageNumber = (isset($_GET['page']) &amp;&amp; is_numeric($_GET['page'])) ? $_GET['page'] : 1;

// Establish number of results per page
$perPage = 5;

// Establish a padding value
$padding = 3;

// Get Start index of results
$startIndex = ($pageNumber * $perPage) - $perPage;

// Get total number of database entries
$totalCount = "SELECT COUNT(*) as 'Total' FROM $table $column";
$rsCount = mysql_query($totalCount) or die (mysql_error());
$rowCount = mysql_fetch_object($rsCount);

----- non essential stuff removed -----

// Get page results
$sql = "$query 
        LIMIT $startIndex, $perPage";
// Get result set
$query = mysql_query($sql) or die(mysql_error());

return $query;
}
</code></pre>

<p>In use:</p>

<pre><code>$query = pagination_query("SELECT id, message 
FROM posts WHERE topicid = 1 
ORDER BY id", 'posts', 'WHERE topicid = 1');


if (mysql_num_rows($query)&gt; 0) {
// Show the results
while($row = mysql_fetch_object($query)) {
print "&lt;div&gt;";
print $row-&gt;id;
print ": ";
print substr($row-&gt;message, 0, strrpos(substr($row-&gt;message, 0, 50), ' ')) . '...';
print "&lt;/div&gt;";
} 
}
</code></pre>

<p>I just figured out that with this, I can only print the links in one place on the page.
Any ideas?</p>

<p>What do you guys think of my solution? Is there a smarter and better way?</p>
