I have a pretty nice system in my code which puts my SQL result on different pages, 10 rows on each page. This is great and works exactly the way it should, but I would like to limit the number of pages generated. My result is in a specific order, but after 25 pages I think it's enough (that would be 250 results). What do I add to the code below in order to maximize the amount of pages created? Thanks in advance!
<?php
// First I build my SQL which counts the amount of
// rows, how this SQL query looks like depends on the
// fields left blank and actually filled.
$sql = "SELECT COUNT(bedrijfsnaam) FROM profiles";
if ($bedrijfvariabele != " zoek op bedrijfsnaam.." &&
$bedrijfvariabele != "")
{
$sql .= " WHERE bedrijfsnaam = '".$bedrijfvariabele."'";
}
if ($rubriekvariabele != " zoek op rubriek.." &&
$rubriekvariabele != "" &&
$bedrijfvariabele != " zoek op bedrijfsnaam.." &&
$bedrijfvariabele != "")
{
$sql .= " AND (hoofdrubriek = '" . $rubriekvariabele . "' "
. " OR subrubrieken LIKE '%" . $rubriekvariabele . "%')";
}
if ($rubriekvariabele != " zoek op rubriek.." &&
$rubriekvariabele != "" &&
($bedrijfvariabele == " zoek op bedrijfsnaam.." ||
$bedrijfvariabele == ""))
{
$sql .= " WHERE (hoofdrubriek = '" . $rubriekvariabele . "' "
. " OR subrubrieken LIKE '%".$rubriekvariabele."%')";
}
if ($plaatsvariabele != " zoek op plaatsnaam.." &&
$plaatsvariabele != "" &&
(
($bedrijfvariabele != " zoek op bedrijfsnaam.." &&
$bedrijfvariabele != "") ||
($rubriekvariabele != " zoek op rubriek.." &&
$rubriekvariabele != "")
))
{
$sql .= " AND plaats = '".$plaatsvariabele."'";
}
if ($plaatsvariabele != " zoek op plaatsnaam.." &&
$plaatsvariabele != "" &&
(
($bedrijfvariabele == " zoek op bedrijfsnaam.." ||
$bedrijfvariabele == "") &&
($rubriekvariabele == " zoek op rubriek.." ||
$rubriekvariabele == "")
))
{
$sql .= " WHERE plaats = '".$plaatsvariabele."'";
}
// Now comes the interesting part for you guys
$rs_result = mysql_query($sql);
$row = mysql_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 10);
$template = '<a style="float:none;display:inline-block;color:white;'
. 'width:22px;text-align:center;text-decoration:none;'
. 'font-size:20px;background-color:#483435;margin-left:4px"'
. ' href="%s".php?page=%s">%s</a>';
for ($i=1; $i <= $total_pages; $i++)
{
echo sprintf($template, $plaatsnaam7, $i, $i);
}