Tuesday, November 29, 2016

E-Commerce Website Using PHP!

Customer can view the collection and browse through different category of pearl  jewelry, can view new arrival, can short the jewelry by price and color, can search the product by name, can place an order and track it from a wide range of designs available online.

///////////////////////////////////////////////////////////////////////////////////////////////////
//// index.php
///////////////////////////////////////////////////////////////////////////////////////////////////

<style>
#header:hover{
background-color:#00CCFF;
font-weight:bold}

#pimg:hover{background-color:#FF66CC}
</style>


<?php
session_start();
include("db.php");
$obj=new DB;
//-----------header--------------------------------
$sql="select * from category";
$cats=$obj->GetSqlTable($sql);
$numcat=count($cats);
//------------old-------------------------------
unset($_SESSION['numofprotodisp']);
//--New----------------------------------------

if(isset($_REQUEST['id'])){
$id=$_REQUEST['id'];}
else
$id=1;
$sql="select * from product where cat_id=".$id." limit 0,6";
$prods=$obj->GetSqlTable($sql);
$numpro=count($prods);


$sql="select * from product where cat_id=".$id;
$fullpro=$obj->GetSqlTable($sql);
$num=count($fullpro);
$_SESSION['numpro']=$num;
$round=ceil($num/3);
//----------end new-------------------------
?>

<table>
<!--header-->
  <tr>
        <table bgcolor="#FF3366" width="100%" border="1" cellpadding="1" cellspacing="1">
<h2 align="center"><font color="#660033">THE ECCOMERCE SITE</font></h2>
 <tr>
 <?php for($i=0;$i<$numcat;$i++){?>
 <td align="center" id="header" height="40" align="center"><a href="index.php?id=<?php echo $cats[$i]['cat_id']?>"><?php echo ucfirst($cats[$i]['cat_name'])?></a></td>
 <?php }?>
 </tr>
 </table>
 <?php $total=0;
 if(isset($_SESSION['cart'])){
 foreach($_SESSION['cart'] as $key=>$val)
   { $total=$total+$val;}
 }
 // onClick="window.location='mycart.php'"
 ?>
 <img src="icons/mycart.png" align="right" width="70" height="70" onClick="window.location='mycart.php'"/><br/><br/><br/><br/>
 <div id="mycart" align="right" onClick="window.location='mycart.php'">My Cart(<?php echo $total;?>)</div>
  </tr>
  <!--header end-->
                       <h3  align="center"><strong>Muna Practice of Pagination</strong></h3>
  <div align="center">

  Category:<select onchange="byCat(this.value)">
   <option value="" "selected='selected'">Categories</option>
   <?php foreach($cats as $cat){?>
  <option value=" <?php echo $cat['cat_id']?>"> <?php echo $cat['cat_name']?></option>
   <?php }?>
  </select>
  Sort:<select onchange="sortby(this.value)">
   <option value="" "selected='selected'">Sort By</option>
  <option value="DESC">High to Low</option>
  <option value="ASC">Low to High</option>
  </select>
  Classification:<select onchange="selClassif(this.value)">
   <option value="" "selected='selected'">Select Classif</option>
  <option value="PARTY">PARTY</option>
  <option value="FESTIVE">FESTIVE</option>
  <option value="YOUTH COLLECTION">YOUTH COLLECTION</option>
  <option value="CASUAL">CASUAL</option>
  <option value="WEDDING COLLECTION">WEDDING COLLECTION</option>
  <option value="FOR MOMS">FOR MOMS</option>
  <option value="CORPORATE COLLECTION">CORPORATE COLLECTION</option>
  </select>
  Price:<select onchange="selPrice(this.value)">
   <option value="" "selected='selected'">Select Price</option>
  <option value="0-1000">Below 1000</option>
  <option value="1000-1200">1000-1200</option>
  <option value="1201-1400">1201-1400</option>
  <option value="1401-1600">1401-1600</option>
  <option value="1601-1800">1601-1800</option>
  <option value="1800-3000">Above 1800</option>
  </select><br/>
  Showing<select id="numofitem" onchange="loadPagi(this.value)">
    <?php for($i=3;$i<=$num+3;$i+=3){?>
      <option value="<?php echo $i;?>"><?php echo $i;?></option>
      <?php }?>
  </select>Entries Per Page:
  </div>
<!--body-->

     <div id="dynpart">
      <table border="1" cellpadding="1" cellspacing="1" align="center">
     <?php
 for($i=0;$i<$numpro;$i++){
 $coltd="";
 if($i%3==0){
 $r=3;
     echo'<tr>';
 }
 //$prods[$i]['prod_id']
 $coltd.="<td id='pimg'><img src='snaps/".$prods[$i]['image']."' width='200' height='200' onclick=\"window.location='enlarge.php?id=".$prods[$i]['prod_id']."'\"><br/>";
 $coltd.=$prods[$i]['name']."<br/>";
 $coltd.="$".$prods[$i]['price'];
 //dynamic portion
       $flag=0;
       if(isset($_SESSION['cart'])){
         foreach($_SESSION['cart'] as $key=>$val){
           if($key==$prods[$i]['prod_id']){  //many key but one i like 1001
        $flag=1;
           }
     }
  }
 if($flag==1){
 $coltd.="<img  id='cartimg_".$prods[$i]['prod_id']."' src='icons/removecart.jpg' width='70' height='20' align='right' onclick='cartfun(".$prods[$i]['prod_id'].")'>";
 }
 else{
 $coltd.="<img  id='cartimg_".$prods[$i]['prod_id']."' src='icons/addtocart.jpg' width='70' height='20' align='right' onclick='cartfun(".$prods[$i]['prod_id'].")'>";
 }

//dynamic portion end
 $coltd.="</td>";
 echo $coltd;
 $r--;
 if($r==0){
  echo'</tr>';
 }
 
  }
  ?>
  </table>

<!--body end-->
<!--footer-->
   <div id="pagi" align="center">
 <!--dynamic end-->

 <?php
 for($i=1;$i<=3;$i++){
 ?>


<button style="background-color:#33FFCC"  onclick="anyPage(<?php echo $i;?>)"><?php if($i==1){?><font color="#CC0000"; size="+2"><?php echo $i;?></font> <?php } else {echo $i;}?></button>
 <?php }?>

 <a href="javascript:void(0)" onclick="anyPage(<?php echo 1+1;?>)"><img src="icons/Next.png" height="30" width="30" /></a>
 <a href="javascript:void(0)" onclick="anyPage(<?php echo $round;?>)"><img src="icons/Last.png" height="30" width="30" /></a><br/>
  Showing 0 -10 of <?php echo $_SESSION['numpro'];?> Products
 </div>

 </div>

             


<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
 //global var decl
function loadPagi(numofprotodisp){
// alert(numofprotodisp);
var numofprotodisp=$("#numofitem").val();
 $.ajax({
    type:"POST",
url:"update.php",
data:{"page":1,"numofprotodisp":numofprotodisp},
success:function(data){
$("#dynpart").html(data)
}

 });
}


function anyPage(p){
 $.ajax({
    type:"POST",
url:"update.php",
data:{"page":p},
success:function(data){
$("#dynpart").html(data)
}

 });
}


 function cartfun(id){

  if($("#cartimg_"+id).attr("src")=="icons/addtocart.jpg"){
  $("#cartimg_"+id).attr("src","icons/removecart.jpg");
  var action="add";
  }
  else{
   $("#cartimg_"+id).attr("src","icons/addtocart.jpg");
   var action="remove";

  }
  $.ajax({
  url:"updatecart.php",
  type:"POST",
  data:{"action":action,"id":id},
  success:function(data){
    $("#mycart").html("My cart("+data+")");
  }
  });
 }

 function selPrice(price){
 alert(price);
  $.ajax({
    type:"POST",
url:"update.php",
data:{"price":price},
success:function(data){
$("#dynpart").html(data)
}

 });
 }

  function selClassif(clasif){
 alert(clasif);
  $.ajax({
    type:"POST",
url:"update.php",
data:{"clasif":clasif},
success:function(data){
$("#dynpart").html(data)
}

 });
 }
   function sortby(sortval){
 alert(sortval);
  $.ajax({
    type:"POST",
url:"update.php",
data:{"sortval":sortval},
success:function(data){
$("#dynpart").html(data)
}

 });
 }


  function byCat(catid){
 alert(catid);
  $.ajax({
    type:"POST",
url:"update.php",
data:{"catid":catid},
success:function(data){
$("#dynpart").html(data)
}

 });
 }

 </script>

///////////////////////////////////////////////////////////////////////////////////////////////////
//// End index.php
///////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
//// db.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Muna ECOMMERCE DATABASE FUNCTION Library
///////////////////////////////////////////////////////////////////////////////////////////////////
//// Database Functions
///////////////////////////////////////////////////////////////////////////////////////////////////
////
//// Usage:
//// $db = new DB(); //instantiate using default read-only connection
//// $db = new DB($user,$pass); //instantiate using a specific login/pass
////
///////////////////////////////////////////////////////////////////////////////////////////////////

$showsql = true;
//$db = new DB();

class DB {
  private $dbhost = "localhost";
  private $dbuser = "root";
  private $dbpass = "";
  private $dbname = "yourdbname";

  public $error = "";

  function __construct()
    {
    }


//print json_encode($rows, JSON_NUMERIC_CHECK);
//---------------
public function ReportError ($sql, $message) {
//echo "SQL ERROR:\nMessage: $message\nSQL: $sql\n";
$this->error = $message;
}

//highchart
public function GetChart ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
$rows = Array();
    while ($res = mysql_fetch_object($result))
//will ignore anything that comes after
{
    $row[0]=$res->year;
             $row[1]=$res->amount;
//$row[1]=$channel->Date;
             array_push($rows,$row);
//array_push(array,value1,value2...)

}
    mysql_close($con);
//print_r($rows);
    print_r(json_encode($rows, JSON_NUMERIC_CHECK));
    }
//delete by muna

public function deleteRow($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
mysql_select_db($this->dbname, $con);
//mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
mysql_close($con);
return $result;
}
//by muna
public function GetSqlTable ($sql)
    {
    $data = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_assoc($result))
//will ignore anything that comes after
{
$data[] = $row;
}
    mysql_close($con);
    return $data;
    }

public function InsertSql ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result) {$output= 1;}
else $output= 0;
 
    mysql_close($con);
    return $output;
    }


//returns a 1d list of results (using the first column returned)
public function GetList2 ($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
//mysql_select_db("esigns_prod", $con);
$result = mysql_query($sql, $con);
while ($row = mysql_fetch_array($result)) {
$results[] = $row[0];
}
mysql_close($con);
return $results;
}



public function GetRow2 ($sql) {
$con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
if (!$con) {
die("Could not connect to database!");
}
$con = $this->GetDB();
$result = mysql_query($sql, $con);
return mysql_fetch_assoc($result);
}


  public function GetDB ()
    {
    $con = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass);
    if (!$con)
          {
          die("Could not connect to database!");
          }
    mysql_select_db($this->dbname, $con);
    return $con;
    }


  public function Clean($sql)
         {
         return mysql_real_escape_string($sql, $this->GetDB());
         }


  public function Query ($sql)
    {
    $output=0;
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if (!isset($result))
          {
          return 0;
          }
    if (!$result) {return 0;}
    if ($row = mysql_fetch_row($result))
      {
        $output = $row[0];
      }
    mysql_close($con);
    return $output;
    }

  //returns the first two columns in an sql query as a keyed array
  public function GetArray ($sql)
        {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
      {
  //verify there are two rows of data, otherwise return an indexed list of the first
            $output[$row[0]] = $row[1];
      }
    mysql_close($con);
    return $output;
        }
  //returns the first column of each row returned
  public function GetList ($sql)
        {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
      {
            array_push($output, $row[0]);
      }
    mysql_close($con);
    return $output;
        }


  public function GetResult ($sql)
    {
    $con = $this->GetDB();
    if (!$con) {return 0;}
    $result = mysql_query($sql, $con);
    //mysql_close($con);
    return $result;
    }


public function GetJSON ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
//will ignore anything that comes after
{
$data = Array();
for ($i=0; $i<mysql_num_fields($result);  $i++) {
$data[mysql_fetch_field($result, $i)->name] = $row[$i];
}
array_push($output, $data);
}
    mysql_close($con);
    return json_encode($output);
    }

public function GetTable ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
//will ignore anything that comes after
{
$data = Array();
for ($i=0; $i<mysql_num_fields($result);  $i++) {
$data[mysql_fetch_field($result, $i)->name] = $row[$i];
}
array_push($output, $data);
}
    mysql_close($con);
    return $output;
    }








  public function GetRow ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    if ($row = mysql_fetch_row($result))
//will ignore anything that comes after
      {
                $output = $row;
      }
    mysql_close($con);
    return $output;
    }

  public function GetRowObject ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    if ($row = mysql_fetch_assoc($result))
//will ignore anything that comes after
      {
                $output = $row;
      }
    mysql_close($con);
    return $output;
    }


  public function GetRows ($sql)
    {
    $output = Array();
    $con = $this->GetDB();
    if (!$con) {return -1;}
    $result = mysql_query($sql, $con);
    if ($result == 0) {return 0;}
    while ($row = mysql_fetch_row($result))
//will ignore anything that comes after
      {
array_push($output, $row);
      }
    mysql_close($con);
    return $output;
    }


  public function Command ($sql)
    {
global $showsql;
$this->error = "";
//if ($showsql) {echo "SQL: $sql\n";}
    $con = $this->GetDB();
    if (!$con) {return 0;}
    $result = mysql_query($sql, $con);
    $rows = mysql_affected_rows($con);
        if ($rows < 1)
          {
 $this->error = mysql_error($con);
 //$this->ReportError($sql, mysql_error($con));
          //echo "DB ERROR: " . mysql_error($con) . "\n";
          }
    mysql_close($con);
    return $rows;
    }





}
?>

///////////////////////////////////////////////////////////////////////////////////////////////////
//// End db.php
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
//// updatecart.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
session_start();
if(isset($_REQUEST['qty'])){
  $qty=$_REQUEST['qty'];
}
$id=$_REQUEST['id'];
$action=$_REQUEST['action'];

switch($action){
case "add":
$total=0;
$_SESSION['cart'][$id]=1;
foreach($_SESSION['cart']as $key=>$val){
$total=$total+$val;
}
echo"$total";
   break;

case "update":
$total=0;
$_SESSION['cart'][$id]=$qty;
foreach($_SESSION['cart']as $key=>$val){
$total=$total+$val;
}
echo"$total";
   break;

case "remove":
$total=0;
unset($_SESSION['cart'][$id]);
foreach($_SESSION['cart']as $key=>$val){
$total=$total+$val;
}
echo"$total";
   break;


}
?>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End updatecart.php
///////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
//// update.php
///////////////////////////////////////////////////////////////////////////////////////////////////



<?php


include("db.php");
$obj=new DB;
session_start();

if(isset($_REQUEST['numofprotodisp'])){
$numofprotodisp=$_REQUEST['numofprotodisp'];
$_SESSION['numofprotodisp']=$numofprotodisp;
}
else
{   if(isset($_SESSION['numofprotodisp']))
    {$numofprotodisp=$_SESSION['numofprotodisp'];}
else
{$numofprotodisp=6;}
}


if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
$pageLimit=($_REQUEST['page']-1)*$numofprotodisp;
}
else
{$page=1;
 $pageLimit=1;
}
$numofprotodisp;




//--New----------------------------------------
//echo $numofprotodisp;//9echo $pageLimit;//0
//WHERE column_name BETWEEN value1 AND value2;
//WHERE price BETWEEN ".$p[0]." AND ".$p[1].";


if(isset($_REQUEST['id'])){
       
       $id=$_REQUEST['id'];
     
}
else
{           if(isset($_REQUEST['catid'])){
   $id=$_REQUEST['catid'];
   }
            else
            {$id=1;}
}
$sql="select * from product where cat_id=".$id ;
/***************Price Sort********************************/
if(isset($_REQUEST['price'])){
$price=$_REQUEST['price'];
$p=explode("-",$price);
//echo $p[0];echo $p[1];
$sql.=" and price BETWEEN ".$p[0]." AND ".$p[1];

}

/***************Classif ********************************/
if(isset($_REQUEST['clasif'])){
$clasif=$_REQUEST['clasif'];

$sql.=" and classification ='".$clasif."'";

}
/***************Classif End********************************/
/**************ASC/DESC**************/
if(isset($_REQUEST['sortval'])){
$sortval=$_REQUEST['sortval'];
$sql.=" ORDER BY price ".$sortval;
}
echo $sql.=" limit ".$pageLimit.",".$numofprotodisp;
/***************Price Sort End********************************/

$prods=$obj->GetSqlTable($sql);
$numpro=count($prods);
//----------end new-------------------------

//********************************footer********************************
$sql="select * from product where cat_id=".$id;
$fullpro=$obj->GetSqlTable($sql);
$num=count($fullpro);
$round=ceil($num/$numofprotodisp);
//********************************footer End********************************
?>

      <!--body-->
<h3  align="center"><strong>Next Page</strong></h3>
     <div id="dynpart">
      <table border="1" cellpadding="1" cellspacing="1" align="center">
     <?php
 for($i=0;$i<$numpro;$i++){
 $coltd="";
 if($i%3==0){
 $r=3;
     echo'<tr>';
 }
 //$prods[$i]['prod_id']
 $coltd.="<td id='pimg'><img src='snaps/".$prods[$i]['image']."' width='200' height='200' onclick=\"window.location='enlarge.php?id=".$prods[$i]['prod_id']."'\"><br/>";
 $coltd.=$prods[$i]['name']."<br/>";
 $coltd.="$".$prods[$i]['price'];
 //dynamic portion
       $flag=0;
       if(isset($_SESSION['cart'])){
         foreach($_SESSION['cart'] as $key=>$val){
           if($key==$prods[$i]['prod_id']){  //many key but one i like 1001
        $flag=1;
           }
     }
  }
 if($flag==1){
 $coltd.="<img  id='cartimg_".$prods[$i]['prod_id']."' src='icons/removecart.jpg' width='70' height='20' align='right' onclick='cartfun(".$prods[$i]['prod_id'].")'>";
 }
 else{
 $coltd.="<img  id='cartimg_".$prods[$i]['prod_id']."' src='icons/addtocart.jpg' width='70' height='20' align='right' onclick='cartfun(".$prods[$i]['prod_id'].")'>";
 }

//dynamic portion end
 $coltd.="</td>";
 echo $coltd;
 $r--;
 if($r==0){
  echo'</tr>';
 }
 
  }
  ?>
  </table>

<!--body end-->
    <div id="pagi" align="center">
 <!--dynamic end-->
 <?php

 if($page>1){?>
 <a href="javascript:void(0)" onclick="anyPage(1)"><img src="icons/first.jpg" height="30" width="30" /></a>
 <a href="javascript:void(0)" onclick="anyPage(<?php echo $page-1;?>)"><img src="icons/prev.png" height="30" width="30" /></a>
 <?php }//if end
 for($i=$page-2;$i<=$page+2;$i++){
if($i>=1&& $i<=$round){
 ?>

<button style="background-color:#33FFCC"  onclick="anyPage(<?php echo $i;?>)"><?php if($i==$page){?><font color="#CC0000"; size="+2"><?php echo $i;?></font> <?php } else {echo $i;}?></button>
 <?php }

 }

 $j=$i-2;
 if($j<=$round){
 //echo $round;
 //echo $j;
 //echo $round;//19

 ?>

 <a href="javascript:void(0)" onclick="anyPage(<?php echo $page+1;?>)"><img src="icons/Next.png" height="30" width="30" /></a>
 <a href="javascript:void(0)" onclick="anyPage(<?php echo $round;?>)"><img src="icons/Last.png" height="30" width="30" /></a>
 <?php }?><br/>
 Showing <?php echo $pageLimit;?> -<?php echo $pageLimit+$numofprotodisp;?> of <?php echo $_SESSION['numpro'];?> Products
 </div>

                     <!--end to be sent in next page--->
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End update.php
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
//// mycart.php
///////////////////////////////////////////////////////////////////////////////////////////////////
<?php
session_start();
include("db.php");
$obj=new DB;
//echo'<pre>'; print_r($_SESSION['cart']);
//foreach($_SESSION['cart'] as $key=>val){}
?>
<table>
 <tr>
        <table border="1" align="center" width="65%">
<h3 align="center"><strong>Displaying the  details of item in your cart!</strong></h3>
   <tr>
   <td align="center" bgcolor="#339933" height="40"><strong>Sln</strong></td>
<td align="center" bgcolor="#339933" height="40"><strong>Product</strong></td>
<td align="center" bgcolor="#339933" height="40"><strong>Quantity</strong></td>
<td align="center" bgcolor="#339933" height="40"><strong>Price</strong></td>
<td align="center" bgcolor="#339933" height="40"><strong>Total</strong></td>
<td align="center" bgcolor="#339933" height="40"><strong>Remove</strong></td>
   </tr>
<?php 
 $cntr=1;
 $totalBuy=0;
 $totalQty=0;
 foreach($_SESSION['cart'] as $key=>$val){
 $totalQty=$totalQty+$val;
 $id=$key;
 $sql="select * from product where prod_id=".$id;
 $prod=$obj->GetSqlTable($sql);
 //echo'<pre>'; print_r($prod);
?>
<tr>
   <td align="center"  bgcolor="#99FFFF"><?php echo $cntr;?>
</td>
<td align="center"  bgcolor="#99FFFF"><img src="snaps/<?php echo $prod[0]['image'];?>" align="center" width="30" height="30" >
</td>
<!-- qty start here-->
<td align="center"  bgcolor="#99FFFF">
<select onchange="update(<?php echo $prod[0]['prod_id'];?>,this.value)">
<?php
for($i=1;$i<$prod[0]['quantity']; $i++){
?>
<option  <?php if($i==$val) echo 'selected="selected"'?>value="<?php echo $i;?>"><?php echo $i;?></option>
<?php }?>
</select>
</td>
   <!-- qty end here-->
<td align="center"  bgcolor="#99FFFF"><?php echo $prod[0]['price'];?>
</td>
   <?php $totalBuy=$totalBuy +$val * $prod[0]['price'];?>
<td align="center"  bgcolor="#99FFFF"><?php echo $val * $prod[0]['price'];?>
</td>
<td align="center"  bgcolor="#99FFFF" ><img src="icons/del.png" align="center" width="25" height="25" >
</td>
 
</tr>
<?php
 $cntr++;
 }
 ?>
<!--Dynamic end-->
 <tr>
   <td colspan="2" align="center" bgcolor="#336633"><strong>Total</strong>
</td>
<td colspan="1" align="center" bgcolor="#336633"><strong><?php echo  $totalQty;?></strong>
</td>
<td colspan="3" align="center" bgcolor="#336633"><strong><?php echo  $totalBuy;?></strong>
</td>
</tr>
 
 <tr>
   <td colspan="6" bgcolor="#CC66CC"> <img src="icons/continue.jpg" align="left" width="80" height="25" onclick="window.location='index.php'"><img src="icons/payment.jpg" align="right" width="80" height="25">
</td>
</tr>
</table>
 </tr>
</table>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
function update(id,val){
  $.ajax({
    url:"midcart.php",
type:"POST",
data:{"action":"update","id":id,"qty":val},
success:function(){
window.location.reload();
}
  });
}
</script>
///////////////////////////////////////////////////////////////////////////////////////////////////
//// End mycart.php
///////////////////////////////////////////////////////////////////////////////////////////////////



No comments:

Post a Comment