Jump to content


Photo

Searching on page..


  • Please log in to reply
No replies to this topic

#1 dannel77

dannel77
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 20 July 2006 - 11:07 AM

Hi,
I need some help to modify this script so people can make a search on article number (code_no) on my companys homepage, currently only item name and 'maingroup', 'secondgroup' can be searched for. I'd really appreciate any kind of help. The code looks like this:

<?php
// required variables
require("config.php");

$chose_allowed = array('item', 'maingroup', 'secondgroup');
$chose = isset($_GET['chose']) && in_array($_GET['chose'], $chose_allowed) ? $_GET['chose'] : $chose_allowed[0];

$searchstring = isset($_GET['searchstring']) ? mysql_escape_string($_GET['searchstring']) : '';


?>

<html>
<head>

<title>Search List</title>

<link rel="stylesheet" HREF="master_style.css">
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000000" VLINK="#000000" ALINK="#F70404">

<FORM NAME="itemsform">

<CENTER>
<font style="font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;">
<?php echo $txt_search_result ?> "<?php echo $searchstring ?>"</FONT>

<HR WIDTH=95% size=1 COLOR="#000000">


<center>
<?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 = 40; // Antal per sida
$where = "$chose LIKE '%$searchstring%'";

$result = @mysql_query("SELECT COUNT(*) FROM products WHERE $where")
or die("Error fetching number in DB<br>".mysql_error());
$numrows = @mysql_result($result, 0); // Antal i databasen

// Sedan kollar vi om startvariabeln är satt
$start = isset($_GET['start']) && intval($_GET['start']) >= 0 ? intval($_GET['start']) : 0;

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

$numlink = '';

// Hämta länk till föregående sida
if ($start > 0) {

$numlink .= '<a href="?start='.($start - $limit).'&amp;searchstring='.$searchstring.'">&laquo; </a> ';
} else {
$numlink .= '&laquo; ';
}

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

// Hämta länk till nästa sida
if ($numrows > ($start + $limit))
$numlink .= '<a href="?start='.($start + $limit).'&amp;searchstring='.$searchstring.'"> &raquo;</a> ';
else
$numlink .= ' &raquo; ';

$numlink = '
<div style="font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; padding: 5px 0;">
'.$numlink.'
</div>
';

// Skriv ut sidorna
echo $numlink;

?>
<table cellpadding="2" cellspacing="1" border="1" frame="border" RULES="NONE" borderstyle="color: #D5E2EC;">
<TR><TD BGCOLOR="#D5E2EC">
<TD BGCOLOR="#D5E2EC" ALIGN="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="-2" color="Black"><b> Art nr. </b></FONT></TD>
<TD BGCOLOR="#D5E2EC" ALIGN="left"><font face="Verdana, Arial, Helvetica, sans-serif" size="-2" color="Black"><b> Titel </b></FONT></TD>
<TD BGCOLOR="#D5E2EC" ALIGN="right"><font face="Verdana, Arial, Helvetica, sans-serif" size="-2" color="Black"><b> Pris SEK </b></FONT></TD>
<TD BGCOLOR="#D5E2EC"></TD></TR>
<?php
// Nu kan vi hämta datan från databasen och skriva ut den
$result = @mysql_query("SELECT * FROM products WHERE $where ORDER BY item ASC 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\"> $row[2] </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\"> $row[3] </FONT></TD>";
echo "<TD ALIGN=\"right\"></a><font style=\"font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;\"> $row[5] </font></TD>";
echo "<TD ALIGN=\"middle\"> <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> </TD></TR>";
}
"</center>"
?>
</TABLE>

<?php echo $numlink ?>

<HR WIDTH=95% size=1 COLOR="#000000">

<TABLE BORDER=0 CELLSPACING=2 CELLPADDING=4>
<TR>
<TD><font style="font-size: 10px; font-family: Verdana, Arial, Helvetica, sans-serif;"><b>| <a href="basket.php"><?php echo $txt_view_cart ?></a> |
<a href="order.php"><?php echo $txt_checkout ?></a> |</b></TD></TR></TABLE>
</font>
</CENTER>
</FORM>
</body>
</html>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users