Forum Moderators: coopster
In the code below I am populating results based on the search criteria. As you can see there is a checkbox in front of each item..Now I want to do something like a shopping cart where a user can select an item and it pops up a box in which the item is listed with the quantity and its price ...he should be able to configure the quantity and the price should be updated accordingly...user can select multiple items from the list... the shopping bag should be on the right side of the same page..I dont have to do all the till the checkout process but the shopping cart should be exported as an excel file to save on a local system...
<?php
//error handling
//ini_set('error_reporting',E_ALL);
//ini_set('display_errors',1);
include 'main_new.php';
include_once('../inludes/db.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="../builder/chassis/css/table.css" />
<script src="js/sorttable.js"></script>
<title>Search</title>
</head>
<body>
<form name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="text" name="q" />
<input type="submit" name="Submit" value="Search" />
</form>
<?php
// Get the search variable from URL
$var = (!empty($_GET['q'])) ? mysql_real_escape_string(trim($_GET['q'])) : '';
// rows to return
$limit=25;
// check for an empty string and display a message.
if (empty($var))
{
echo "<p>Please enter a search...</p>";
exit;
}
// Build SQL Query
$query = "SELECT ID,name,description,vendor,IFNULL(price,'N/A')price,IFNULL(cost,'N/A')cost,IFNULL(category,'N/A')category,IFNULL(subcategory,'N/A')subcategory FROM prices WHERE name LIKE '%$var%' OR description LIKE '%$var%' OR vendor LIKE '%$var%' OR category LIKE '%$var%' OR subcategory LIKE '%$var%'";
//$query = "SELECT * FROM prices WHERE name LIKE '%$var%' OR description LIKE '%$var%' OR vendor LIKE '%$var%' OR category LIKE '%$var%' OR subcategory LIKE '%$var%'"; // 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 "<h4>Results</h4>";
echo "<p>Sorry, your search: "" . $var . "" returned zero results</p>";
}
// next determine if s has been passed to script, if not use 0
$s = (!empty($_GET['s'])) ? intval($_GET['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>Your search results for <strong> "" . $var . ""</strong> are as below..</p>";
// begin to show results set
//echo "<h4>Results</h4>";
$count = 1 + $s ;
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$_SERVER[PHP_SELF]?s=$prevs&q=$var\"><<
Prev $limit</a>  ";
}
// 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 " <a href=\"$_SERVER[PHP_SELF]?s=$news&q=$var\">Next $limit >></a>";
}
// now you can display the results returned
/*while ($row= mysql_fetch_array($result)) {
$title = $row["name"];
echo "$count.) $title<br>" ;
$count++ ;
}
*/
if(mysql_num_rows($result) )
{
echo "<table width=50% border=1 class=sortable>";
echo "<tr><th> </th><th>No</th><th>Name</th><th>Description</th><th>Vendor</th><th>List Price</th><th>Street Price</th><th>Category</th><th>Sub Category</th></tr>";
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
if($row['cost']=="N/A") {$dol1="";} else {
$dol1 = "$"; }
$dol = "$";
echo "<tr><td><input type='checkbox' name='price[]' value='{$row['ID']}' /></td><td>{$count}</td><td>{$row['name']}</td><td>{$row['description']}</td><td>{$row['vendor']}</td><td>$dol{$row['price']}</td><td>$dol1{$row['cost']}</td><td>{$row['category']}</td><td>{$row['subcategory']}</td></tr>";
$count++ ;
}
echo "</table>";
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href=\"$_SERVER[PHP_SELF]?s=$prevs&q=$var\"><<
Prev $limit</a>  ";
}
// 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 " <a href=\"$_SERVER[PHP_SELF]?s=$news&q=$var\">Next $limit >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
?></body>
</html>