Jump to content

Archived

This topic is now archived and is closed to further replies.

dannel77

Help with search script..please!

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Not unless you tell us what you meen by [i]isn't working[/i].

Are you getting any errors? What are they?

Share this post


Link to post
Share on other sites
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) [snapback]363294[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Not unless you tell us what you meen by [i]isn't working[/i].

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.