[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Creating something like a shopping cart

Asked by PranjalShah in PHP Scripting Language, Miscellaneous Web Development

Tags: web development, php, mysql, AJAX

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...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
<?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: &quot;" . $var . "&quot; 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> &quot;" . $var . "&quot;</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\">&lt;&lt; 
  Prev $limit</a>&nbsp ";
  }
 
// 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 &gt;&gt;</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\">&lt;&lt; 
  Prev $limit</a>&nbsp ";
  }
 
// 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 &gt;&gt;</a>";
  }
 
$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  
?></body>
</html>
[+][-]11/03/09 01:42 PM, ID: 25734118Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 01:55 PM, ID: 25734231Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 04:47 PM, ID: 25735465Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 06:18 PM, ID: 25735843Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 06:32 PM, ID: 25735905Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 10:16 AM, ID: 25742145Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 01:42 PM, ID: 25744262Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 01:56 PM, ID: 25744409Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 08:23 PM, ID: 25746756Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/09 02:38 PM, ID: 25799926Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/11/09 02:39 PM, ID: 25799944Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/13/09 08:14 AM, ID: 25815124Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625