http://www.designplace.org/scripts.php?page=1&c_id=25
my code:
Expand|Select|Wrap|Line Numbers
- <?php
- // Get the search variable from URL
- $var = @$_GET['KEYWORDS'] ;
- $trimmed = trim($var); //trim whitespace from the stored variable
- // rows to return
- $limit=8;
- // check for a search parameter
- if (!isset($var))
- {
- echo "<p>Our online inventory doesn't currently contain what you're looking for. Please visit a store for complete selection.</p>";
- exit;
- }
- mysql_connect("sql002.choiceone.net","roomfulexpress","x47rkv7N"); //(host, username, password)
- mysql_select_db("roomfulexpress") or die("Unable to select database"); //select which database we're using
- // Build SQL Query
- $query = "select * from tblIndividualItem where KEYWORDS like \"%$trimmed%\"
- order by ITEM_NAME"; // EDIT HERE and specify your table and field names for the SQL query
- $numresults=mysql_query($query);
- $numrows=mysql_num_rows($numresults);
- // If we have no results, offer a google search as an alternative
- if ($numrows == 0)
- {
- echo "<p>Our online inventory doesn't currently contain what you're looking for. Please visit a store for complete selection.</p>";
- }
- // next determine if s has been passed to script, if not use 0
- if (empty($s)) {
- $s=0;
- }
- // get results
- $query .= " limit $s,$limit";
- $result = mysql_query($query) or die("Couldn't execute query");
- // display what the person searched for
- echo "<p>Search for: " . $var . "</p>";
- // begin to show results set
- echo "<p>Results</p>";
- $count = 1 + $s ;
- // now you can display the results returned
- while ($row = mysql_fetch_array($result))
- {
- echo("<table>");
- echo("<tr>");
- echo("<TD class=noOverflow width=150px><a href=itemprofile.php?SKU=". $row["SKU"] . " target=content> <img src= " . $row["TN"] . " alt=click to view profile /></a></TD>");
- echo("</tr>");
- echo("<tr>");
- echo("<TD width=150px><h1> " . $row["ITEM_NAME"] . "</h1></TD>");
- echo("</tr>");
- echo("<tr>");
- echo("<TD width=150px> $" . $row["ITEM_PRICE"] . "</TD>");
- echo("</tr>");
- }
- echo("</table>");
- $currPage = (($s/$limit) + 1);
- //Link to other results
- echo("<div class=nextPrev>");
- if ($s>=1) { // bypass PREV link if s is 0
- $prevs=($s-$limit);
- print "<p> <a href=\"$PHP_SELF?s=$prevs&KEYWORDS=$var\"><<
- Prev</a></p>";
- }
- // calculate number of pages needing links
- $pages=intval($numrows/$limit);
- // $pages now contains int of pages needed unless there is a remainder from division
- if ($numrows%$limit) {
- // has remainder so add one page
- $pages++;
- }
- // check to see if last page
- if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
- // not last page so give NEXT link
- $news=$s+$limit;
- echo "<p> <a href=\"$PHP_SELF?s=$news&KEYWORDS=$var\">Next >></a></p>";
- }
- $a = $s + ($limit) ;
- if ($a > $numrows) { $a = $numrows ; }
- $b = $s + 1 ;
- echo "<p>Showing items $b - $a of $numrows items</p>";
- echo "</div>";
- ?>