Forum Moderators: coopster
<?php
include('file to connect to db');
$cxn = mysqli_connect($host,$user,$passwd,$dbname) or die ("couldn't connect to server" . mysqli_error());
$page = (!isset($_GET['page']))? 1 : $_GET['page'];
$prev = ($page - 1);
$next = ($page + 1);
$max_results = 35;
$from = (($page * $max_results) - $max_results);
$searchstring = mysqli_real_escape_string($cxn, $_POST['searchstring']);
$searchstring = rtrim($searchstring, 's');
$searchterm = explode(' ', $searchstring);
$query="SELECT * FROM table WHERE MATCH (`vendor_name`, `color_name`, `style_no`, `desc`, `style_desc`) AGAINST ('";
$i=0;
foreach ($searchterm as $word) {
$query .= "+".$word."* ";
}
$query .= "' IN BOOLEAN MODE) LIMIT $from, $max_results";
echo "<p class='red'>You searched for $searchstring</p>";
echo "<p> </p>";
$result = mysqli_query($cxn,$query);
{
$numcols=7;
$numrows=5;
$i=0;
$ii=0;
$trout=0;
echo "<table id='styles' cellspacing='0' align='center'>";
while ($row = mysqli_fetch_array($result))
{
if ($ii<$numrows) {
if ($trout==0){
echo "<tr>";
$trout=1;
}
if ($i<$numcols){
$desc = $row ['desc'];
$vendor = $row ['vendor_name'];
$color = $row ['color_name'];
$styleno = $row ['style_no'];
$img = $row ['photo_sm'];
$url = $row ['order_url'];
echo "<td align='center' valign='top'>";
echo "<p class='botstyle'>$vendor</p>";
echo "<p class='botstyle'>Style #$styleno</p>";
echo "<p class='botstyle'>$color</p>";
echo "<a href='../$url'>";
echo "<img src='../images/$img' border='0' alt='$desc' title='$desc'>";
echo "</a></p>";
echo "<p class='botstyle'>$desc</p></td>";
$i++;
}
$endtr=$numcols-1;
if ($i==$endtr){
echo "</tr>";
$i=0;
$trout=0;
$ii++;
}
}
}
}
$total_results = mysqli_num_rows($result);
$total_pages = ceil($total_results / $max_results);
$pagination = '';
if($page > 1)
{
$pagination .= '<a href="match4.php?page='.$prev.'"><< Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="match4.php?page='.$i.'"><b> '.$i.' </b></a>';
}
}
if($page < $total_pages)
{
$pagination .= '<a href="match4.php?page='.$next.'">Next >></a>';
}
echo "<tr>";
echo "<td colspan='7' align='center'>$pagination</td>";
echo "</tr>";
echo "</table>";
?>
I was under the impression that was the maximum results I wanted to display on each page, not the total of all results
$total_results = mysqli_num_rows($result); $total_results = mysqli_num_rows(mysqli_query($cxn,preg_replace('#LIMIT[0-9, ]+#','',$query))); www.mydomain.com/match4.php?page=2
$pagination .= '<a href="match4.php?page='.$i.'&searchstring='.urlencode($_GET['searchstring']).'"><b> '.$i.' </b></a>';
$pagination = '';
if($page > 1)
{
$pagination .= '<a href="match4.php?page='.$prev.'"><< Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="match4.php?page='.$i.'"><b> '.$i.' </b></a>';
}
}
if($page < $total_pages)
{
$pagination .= '<a href="match4.php?page='.$next.'">Next >></a>';
}
$pagination = '';
$search_query = urlencode($_GET['searchstring']);
if($page > 2) {
$pagination .= '<a href="match4.php?searchstring='.$search_query.'&page='.$prev.'"><< Previous</a> ';
} elseif($page == 2) {
$pagination .= '<a href="match4.php?searchstring='.$search_query.'"><< Previous</a> ';
}
/* Loop through the total pages */
for($i = 1; $i <= $total_pages; $i++)
{
if(($page) == $i)
{
$pagination .= $i;
}
else
{
$pagination .= '<a href="match4.php?searchstring='.$search_query.'&page='.$i.'"><b> '.$i.' </b></a>';
}
}
if($page < $total_pages)
{
$pagination .= '<a href="match4.php?searchstring='.$search_query.'&page='.$next.'">Next >></a>';
}
$page = (!isset($_GET['page']) || !is_numeric($_GET['page']))? 1 : $_GET['page'];
if(!isset($_GET['page']) || !is_numeric($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page']
}