Jump to content

Help with search script..please!


dannel77

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!
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.