Jump to content


Photo

Help with search script..please!


  • Please log in to reply
2 replies to this topic

#1 dannel77

dannel77
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 10 April 2006 - 01:51 PM

Hi, could someone tell me why this search script with paging isn't working:

<?php

// database connection
mysql_connect("$host","$user","$pass");

// database selection
mysql_select_db("$database");

// Nu bestämmer vi antal per sida och kollar vi upp totala antalet
$limit = 30; // Antal per sida
$result = mysql_query("SELECT COUNT(*) FROM products WHERE $chose LIKE '%$searchstring%'")

or die("Error fetching number in DB<br>".mysql_error());
$row = @mysql_fetch_array($result);
$numrows = $row['count']; // Antal i databasen

// Sedan kollar vi om startvariabeln är satt
if (!isset($_GET['start']) || $_GET['start'] == "")
$start = 0;
else
$start = $_GET['start'];

// Då räknar vi ut hur många sidor det blev
$pages = intval($numrows/$limit);
if ($numrows%$limit)
$pages++;

// Hämta sidonummer
for ($i = 1; $i <= $pages; $i++) {
$newoffset = $limit*($i-1);
if ($start == $newoffset)
$numlink .= '<font color="#000000" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;">|&nbsp;<b>'.$i.'</b></font> ';
else
$numlink .= '<font color="#000000" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;">|&nbsp;</font><a href="?start='.$newoffset.'&amp;maingroup='.$maingroup.'&amp;secondgroup='.$secondgroup.'"><font color="#2B65EC" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;">'.$i.'</font></a> ';
}


// Nu kan vi hämta datan från databasen och skriva ut den
$result = mysql_query("SELECT * FROM products WHERE $chose LIKE '%$searchstring%' ORDER BY 'maingroup', 'secondgroup', 'item' LIMIT $start, $limit") or die("Error fetching data<br>".mysql_error());

while ($row = @mysql_fetch_array($result)){
$color = ($coloralternator++ %2 ? "D5E2EC" : "EBF1F5");
echo "<TR BGCOLOR=\"#$color\"><TD ALIGN=\"middle\"><a href=\"item_show.php?code_no=$row[2]\" TARGET=\"main\"><IMG SRC=\"thumbs/$row[6]\" BORDER=\"0\"></a></TD>";
echo "<TD ALIGN=\"left\"><font style=\"font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;\"><a href=\"item_show.php?code_no=$row[2]\" TARGET=\"main\">&nbsp;$row[2]&nbsp;</FONT></TD>";
echo "<TD ALIGN=\"left\"></a><font style=\"font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;\"><a href=\"item_show.php?code_no=$row[2]\" TARGET=\"main\">&nbsp;$row[3]&nbsp;</FONT></TD>";
echo "<TD ALIGN=\"right\"></a><font style=\"font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;\">&nbsp;$row[5]&nbsp;</font></TD>";
echo "<TD ALIGN=\"middle\">&nbsp;<INPUT TYPE=\"hidden\" NAME=\"id$row[2]quant\" VALUE=\"1\">
<a href=\"Javascript:top.center.cart.addItem('$row[3]','$row[5]', document.itemsform.id$row[2]quant.value, '$row[2]', '$row[7]')\"><img src=\"images/buy.gif\" border=\"0\"></a>&nbsp;&nbsp;</TD></TR>";
}
"</center>"
?>

Any help appreciated!

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 10 April 2006 - 01:53 PM

Not unless you tell us what you meen by isn't working.

Are you getting any errors? What are they?

#3 dannel77

dannel77
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 16 April 2006 - 12:01 PM

The search works, but the paging of the results does not...


[!--quoteo(post=363294:date=Apr 10 2006, 08:53 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Apr 10 2006, 08:53 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Not unless you tell us what you meen by isn't working.

Are you getting any errors? What are they?
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users