dannel77 Posted April 5, 2006 Share Posted April 5, 2006 Hi,I've got this searchscript for a homepage I'm working on, looks like this:<?php// database connectionmysql_connect("$host","$user","$pass");// database selectionmysql_select_db("$database");// database query to select the categories$result = mysql_query("select * from products WHERE $chose LIKE '%$searchstring%' ORDER BY 'maingroup','secondgroup','item' LIMIT 0, 20 ") ;// counter for how many iterations have been done$i=0;while($row = mysql_fetch_row($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>";}?>Could someone please help me modify this with the paging script I'm using for the product list (below). I need the paging to work with the search_list.php as well:<?php// database connectionmysql_connect("$host","$user","$pass");// database selectionmysql_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(*) as count FROM products WHERE maingroup = '$maingroup' AND secondgroup = '$secondgroup'") 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 sattif (!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 sidonummerfor ($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;">| <b>'.$i.'</b></font> '; else $numlink .= '<font color="#000000" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;">| </font><a href="?start='.$newoffset.'&maingroup='.$maingroup.'&secondgroup='.$secondgroup.'"><font color="#2B65EC" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px;">'.$i.'</font></a> ';} // Skriv ut sidornaecho $numlink; // Nu kan vi hämta datan från databasen och skriva ut den$result = @mysql_query("SELECT * FROM products WHERE maingroup = '$maingroup' AND secondgroup = '$secondgroup' 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>"?>Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.