Well, first i have to thank all of you for the tech support you are offering me right here...
i have really spent some time to check out the previous posts on WW regarding pagination but i felt i had to publish my search function hoping someone here will help me with a trip that will definitely change my life.
this is my function
-------------------
function newSearch($searchword)
{
$limit = 12; // items on a page
$page = 1;
if(isset($_GET['page']))
{
$page=$_GET['page'];
}
$query = mysql_query("SELECT ".TBL_PRODS.".*, ".TBL_CAT.".*, ".TBL_GRP.".group_id FROM
".TBL_GRP.", ".TBL_CAT.", ".TBL_PRODS."
WHERE ".TBL_CAT.".cat_id = ".TBL_PRODS.".cat_id AND ".TBL_GRP.".group_id = ".TBL_CAT.".group_id
AND ".TBL_PRODS.".prod_name like '%".mysql_real_escape_string($searchword)."%'
AND ".TBL_PRODS.".isActive = 'Y'
ORDER BY ".TBL_PRODS.".prod_name ASC") or die (mysql_error());
$NumberOfResults = mysql_num_rows($query);
$NumberOfPages = ceil($NumberOfResults/$limit);
$query = "SELECT ".TBL_PRODS.".*, ".TBL_CAT.".*, ".TBL_GRP.".group_id FROM
".TBL_GRP.", ".TBL_CAT.", ".TBL_PRODS."
WHERE ".TBL_CAT.".cat_id = ".TBL_PRODS.".cat_id AND ".TBL_GRP.".group_id = ".TBL_CAT.".group_id
AND ".TBL_PRODS.".prod_name like '%".mysql_real_escape_string($searchword)."%'
AND ".TBL_PRODS.".isActive = 'Y'
ORDER BY ".TBL_PRODS.".prod_name ASC LIMIT ".(($page - 1) * $limit).", $limit";
$result= mysql_query($query);
$self = $_SERVER['PHP_SELF'];
$Nav = "";
if($page > 1)
{
$prev.=" <a href=\"$self?page=".($page-1)."\">previous</a> |";
$first.="<a href=\"$self?page=".($NumberOfPages=1)."\">first</a> |";
}
else
{
$prev = ' ';
$first = ' ';
}
for($i=1; $i <=$NumberOfPages; $i++)
{
if($i==$page)
{
$Nav.="<B>$i</b>";
}
else
{ $Nav.="<a href=\"$self?page=".$i .">$i</a>";
}
}
if($page<$NumberOfPages)
{
$next.=" <a href=\"$self?page=".($page+1)."\">next</a> |";
$last.=" <a href=\"$self?page=".($NumberOfPages)."\" >last</a>";
} else {
$next = ' ';
$last = ' ';//Up to here nothing is printed yet on the browser, pagination only.
}
print '<div id="top_tabla"><strong>::.</strong><span> Search </span></div>
<p>('.$NumberOfResults.') matches found </p>';
if($NumberOfResults == 0)
{ // search did not return any values
print('<p> Sorry, there is currently no item matching your criteria.</p>');
}
// printing navigation if the resultset above holds values
if ($NumberOfResults != 0)
{
print('<div class="nav_number">
viewing page '.$page.' of '.$NumberOfPages.' '.$first.$next.$prev.$last.'
</div>');
}
$numcols =3; // Number of per page
$numcolsprinted = 3; // how many columns we have so far, do not change!
// get the results to be displayed in this set
// get each row
while ($row = mysql_fetch_array($result))
{
$id =$row['prod_id'];
$prod = stripslashes(strtolower($row["prod_name"]));
$price = number_format($format,0,',',',');
$ad_id = $row['ADid'];
// Now query for the thumb nail images
$im = mysql_query("SELECT * FROM ".TBL_IMG." WHERE ADid = '$ad_id' and isThumb = 'Y'") or die(mysql_error());
$rs_img = mysql_fetch_array($im);
$imageurl = $rs_img['file_name'];
if($imageurl=='')
{
$imageurl="nophoto.jpg";
}
// we have to check to see if a row has been completed and if it has, start a new one
if ($numcolsprinted == $numcols)
{
print "<table width=\"95%\" id=\"ad_data\">
<tr><td colspan=\"4\" class=\"spacer\"> </td></tr><tr>";
$numcolsprinted =0;
}
$limiter = 40; //trimming the product name
if(strlen($prod)>$limiter) $prod = substr($prod, 0, strrpos(substr($prod, 0, $limiter), ' ')) . '...';
$link = "products.php?group=".urlencode($row['group_id'])."&cat=".urlencode($row['cat_id'])."
&prod=".urlencode($id)."&adid=".urlencode($row['ADid'])."";
print "<td width=\"30%\">
<a href=\"$link\"> <img src=\"picture/s2-".$imageurl."\" class=\"picAd\"> </a>
<div>
<a href=\"$link\"> ".ucwords($prod)."</a><br /><br />";
if($row['pro_price'] == "")
{
print '<b>'.$row['pro_basis'].'</b><br /><br />';
}
print "</div>
</td>";
$numcolsprinted++; // increment row counter
}// end while loop, at this point we have all the results
// now we need to pad out the table with empty cells if there's a final row with
// fewer results than the number of columns we want to display
$colstobalance = $numcols - $numcolsprinted;
for ($i=1; $i<=$colstobalance; $i++) {
print "<td></td></tr>";
}
print '</table>';
}
-----------
this is how i call the function within search.php
$search = stripslashes($_POST['search']);
if(isset($search))
{
$site->newSearch($search);
}
-----------
@rocknbill - elixduppy's solution works great but when i come to nesting tables i get issues...
Live site: <snip> , try searching something like "f" 28 matches will be found but when i get to next bluuuuuuuu, everything in the table appears..
i feel am missing something small.. so please save me guardian PRO's
[edited by: eelixduppy at 4:08 pm (utc) on Mar 26, 2010]
[edit reason] no personal URLs, please [/edit]