By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

How to work with Add-To-Cart functionality?

aveeva
P: 30
How to work with Add-To-Cart functionality?
My code about filterable audio searching, here how can i add Add-To-Cart functionality?

code :



index.php

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3. //index.php
  4.  
  5. include('database_connection.php');
  6.  
  7. ?>
  8.  
  9. <!DOCTYPE html>
  10. <html lang="en">
  11.  
  12. <head>
  13.  
  14.     <meta charset="utf-8">
  15.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  16.     <meta name="viewport" content="width=device-width, initial-scale=1">
  17.     <meta name="description" content="">
  18.     <meta name="author" content="">
  19.  
  20.     <title>Voice Repository</title>
  21.  
  22.     <script src="js/jquery-1.10.2.min.js"></script>
  23.     <script src="js/jquery-ui.js"></script>
  24.     <script src="js/bootstrap.min.js"></script>
  25.     <link rel="stylesheet" href="css/bootstrap.min.css">
  26.     <link href = "css/jquery-ui.css" rel = "stylesheet">
  27.     <!-- Custom CSS -->
  28.     <link href="css/style.css" rel="stylesheet">
  29. </head>
  30.  
  31. <body>
  32.     <!-- Page Content -->
  33.     <div class="container">
  34.         <div class="row">
  35.             <br />
  36.             <div class="col-md-12">
  37.                 <h2 align="center">Voice Repository Bank</h2>
  38.             </div>
  39.             <div class="col-md-3">
  40.  
  41.                 <!-- Price -->
  42.                 <!-- <div class="list-group">
  43.                     <h3>Price</h3>
  44.                     <input type="hidden" id="hidden_minimum_price" value="0" />
  45.                     <input type="hidden" id="hidden_maximum_price" value="65000" />
  46.                     <p id="price_show">1000 - 65000</p>
  47.                     <div id="price_range"></div>
  48.                 </div> -->
  49.  
  50.                 <!-- Languages  -->
  51.                 <div class="list-group">
  52.                     <h3>Languages</h3>
  53.                     <?php
  54.                     $query = "
  55.                     SELECT DISTINCT(voice_languages) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_languages DESC
  56.                     ";
  57.                     $statement = $connect->prepare($query);
  58.                     $statement->execute();
  59.                     $result = $statement->fetchAll();
  60.                     foreach($result as $row)
  61.                     {
  62.                     ?>
  63.                     <div class="list-group-item checkbox">
  64.                         <label><input type="checkbox" class="common_selector languages" value="<?php echo $row['voice_languages']; ?>"  > <?php echo $row['voice_languages']; ?> </label>
  65.                     </div>
  66.                     <?php
  67.                     }
  68.                     ?>    
  69.                 </div>
  70.  
  71.                 <!-- Genres  -->
  72.                 <div class="list-group">
  73.                     <h3>Genres</h3>
  74.                     <?php
  75.  
  76.                     $query = "
  77.                     SELECT DISTINCT(voice_genres) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_genres DESC
  78.                     ";
  79.                     $statement = $connect->prepare($query);
  80.                     $statement->execute();
  81.                     $result = $statement->fetchAll();
  82.                     foreach($result as $row)
  83.                     {
  84.                     ?>
  85.                     <div class="list-group-item checkbox">
  86.                         <label><input type="checkbox" class="common_selector genres" value="<?php echo $row['voice_genres']; ?>" > <?php echo $row['voice_genres']; ?> </label>
  87.                     </div>
  88.                     <?php    
  89.                     }
  90.  
  91.                     ?>
  92.                 </div>
  93.  
  94.                 <!-- Voice Modulation -->
  95.                 <div class="list-group">
  96.                     <h3>Voice Modulation</h3>
  97.                     <?php
  98.                     $query = "
  99.                     SELECT DISTINCT(voice_voice_modulation) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_voice_modulation DESC
  100.                     ";
  101.                     $statement = $connect->prepare($query);
  102.                     $statement->execute();
  103.                     $result = $statement->fetchAll();
  104.                     foreach($result as $row)
  105.                     {
  106.                     ?>
  107.                     <div class="list-group-item checkbox">
  108.                         <label><input type="checkbox" class="common_selector voice_modulation" value="<?php echo $row['voice_voice_modulation']; ?>"  > <?php echo $row['voice_voice_modulation']; ?> </label>
  109.                     </div>
  110.                     <?php
  111.                     }
  112.                     ?>    
  113.                 </div> 
  114.                 <!-- Gender  -->
  115.                 <div class="list-group">
  116.                     <h3>Gender</h3>
  117.                     <div style="height: 180px; overflow-y: auto; overflow-x: hidden;">
  118.                     <?php
  119.  
  120.                     $query = "SELECT DISTINCT(voice_gender) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_id DESC";
  121.                     $statement = $connect->prepare($query);
  122.                     $statement->execute();
  123.                     $result = $statement->fetchAll();
  124.                     foreach($result as $row)
  125.                     {
  126.                     ?>
  127.                     <div class="list-group-item checkbox">
  128.                         <label><input type="checkbox" class="common_selector gender" value="<?php echo $row['voice_gender']; ?>"  > <?php echo $row['voice_gender']; ?></label>
  129.                     </div>
  130.                     <?php
  131.                     }
  132.  
  133.                     ?>
  134.                     </div>
  135.                 </div>
  136.  
  137.  
  138.                 <!-- Jingle Moods -->
  139.                 <div class="list-group">
  140.                     <h3>Jingle Moods</h3>
  141.                     <?php
  142.                     $query = "
  143.                     SELECT DISTINCT(voice_jingle_moods) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_jingle_moods DESC
  144.                     ";
  145.                     $statement = $connect->prepare($query);
  146.                     $statement->execute();
  147.                     $result = $statement->fetchAll();
  148.                     foreach($result as $row)
  149.                     {
  150.                     ?>
  151.                     <div class="list-group-item checkbox">
  152.                         <label><input type="checkbox" class="common_selector jingle_moods" value="<?php echo $row['voice_jingle_moods']; ?>"  > <?php echo $row['voice_jingle_moods']; ?> </label>
  153.                     </div>
  154.                     <?php
  155.                     }
  156.                     ?>    
  157.                 </div>
  158.  
  159.                 <!-- IVR -->
  160.                 <div class="list-group">
  161.                     <h3>Ivr</h3>
  162.                     <?php
  163.                     $query = "
  164.                     SELECT DISTINCT(voice_ivr) FROM voice_bank_data WHERE voice_status = '1' ORDER BY voice_ivr DESC
  165.                     ";
  166.                     $statement = $connect->prepare($query);
  167.                     $statement->execute();
  168.                     $result = $statement->fetchAll();
  169.                     foreach($result as $row)
  170.                     {
  171.                     ?>
  172.                     <div class="list-group-item checkbox">
  173.                         <label><input type="checkbox" class="common_selector ivr" value="<?php echo $row['voice_ivr']; ?>"  > <?php echo $row['voice_ivr']; ?> </label>
  174.                     </div>
  175.                     <?php
  176.                     }
  177.                     ?>    
  178.                 </div>
  179.             </div>
  180.  
  181.             <div class="col-md-9">
  182.                 <br />
  183.                 <div class="row filter_data">
  184.  
  185.                 </div>
  186.             </div>
  187.         </div>
  188.  
  189.     </div>
  190. <style>
  191. #loading
  192. {
  193.     text-align:center; 
  194.     background: url('loader.gif') no-repeat center; 
  195.     height: 150px;
  196. }
  197. </style>
  198.  
  199. <script>
  200. $(document).ready(function(){
  201.  
  202.     filter_data();
  203.  
  204.     function filter_data()
  205.     {
  206.         $('.filter_data').html('<div id="loading" style="" ></div>');
  207.         var action = 'fetch_data';
  208.  
  209.         // var minimum_price = $('#hidden_minimum_price').val();
  210.         // var maximum_price = $('#hidden_maximum_price').val();
  211.  
  212.         var gender = get_filter('gender');
  213.         var genres = get_filter('genres');
  214.         var voice_modulation = get_filter('voice_modulation');
  215.         var languages = get_filter('languages');
  216.         var jingle_moods = get_filter('jingle_moods');
  217.         var ivr = get_filter('ivr');
  218.         $.ajax({
  219.             url:"fetch_data.php",
  220.             method:"POST",
  221.             data:
  222.             {
  223.                 action:action, 
  224.                 // minimum_price:minimum_price, 
  225.                 // maximum_price:maximum_price,
  226.                 gender:gender,
  227.                 genres:genres, 
  228.                 voice_modulation:voice_modulation,
  229.                 languages:languages,
  230.                 jingle_moods:jingle_moods,
  231.                 ivr:ivr
  232.             },
  233.                 success:function(data)
  234.                 {
  235.                 $('.filter_data').html(data);
  236.                 }
  237.         });
  238.     }
  239.  
  240.     function get_filter(class_name)
  241.     {
  242.         var filter = [];
  243.         $('.'+class_name+':checked').each(function(){
  244.             filter.push($(this).val());
  245.         });
  246.         return filter;
  247.     }
  248.  
  249.     $('.common_selector').click(function(){
  250.         filter_data();
  251.     });
  252.  
  253.     // $('#price_range').slider({
  254.     //     range:true,
  255.     //     min:1000,
  256.     //     max:65000,
  257.     //     values:[1000, 65000],
  258.     //     step:500,
  259.     //     stop:function(event, ui)
  260.     //     {
  261.     //         $('#price_show').html(ui.values[0] + ' - ' + ui.values[1]);
  262.     //         $('#hidden_minimum_price').val(ui.values[0]);
  263.     //         $('#hidden_maximum_price').val(ui.values[1]);
  264.     //         filter_data();
  265.     //     }
  266.     // });
  267.  
  268. });
  269. </script>
  270. </body>
  271. </html>
and my



data fetching file,

data_fetch.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //fetch_data.php
  4.  
  5. include('database_connection.php');
  6.  
  7. if(isset($_POST["action"]))
  8. {
  9.     $query = "
  10.         SELECT * FROM voice_bank_data WHERE voice_status = '1'
  11.     ";
  12.  
  13.     // if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"]))
  14.     // {
  15.     //     $query .= "
  16.     //      AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."'
  17.     //     ";
  18.     // }
  19.  
  20.     // Gender
  21.     if(isset($_POST["gender"]))
  22.     {
  23.         $gender_filter = implode("','", $_POST["gender"]);
  24.         $query .= "
  25.          AND voice_gender IN('".$gender_filter."')
  26.         ";
  27.     }
  28.  
  29.     // Genres
  30.     if(isset($_POST["genres"]))
  31.     {
  32.         $genres_filter = implode("','", $_POST["genres"]);
  33.         $query .= "
  34.          AND voice_genres IN('".$genres_filter."')
  35.         ";
  36.     }
  37.  
  38.     // Voice Modulation
  39.     if(isset($_POST["voice_modulation"]))
  40.     {
  41.         $voice_modulation_filter = implode("','", $_POST["voice_modulation"]);
  42.         $query .= "
  43.          AND voice_voice_modulation IN('".$voice_modulation_filter."')
  44.         ";
  45.     }
  46.  
  47.  
  48.     // Languages
  49.     if(isset($_POST["languages"]))
  50.     {
  51.         $languages_filter = implode("','", $_POST["languages"]);
  52.         $query .= "
  53.          AND voice_languages IN('".$languages_filter."')
  54.         ";
  55.     }
  56.  
  57.     // Jingle Moods
  58.     if(isset($_POST["jingle_moods"]))
  59.     {
  60.         $jingle_moods_filter = implode("','", $_POST["jingle_moods"]);
  61.         $query .= "
  62.          AND voice_jingle_moods IN('".$jingle_moods_filter."')
  63.         ";
  64.     }
  65.  
  66.     // IVR
  67.     if(isset($_POST["ivr"]))
  68.     {
  69.         $ivr_filter = implode("','", $_POST["ivr"]);
  70.         $query .= "
  71.          AND voice_ivr IN('".$ivr_filter."')
  72.         ";
  73.     }
  74.  
  75.     $statement = $connect->prepare($query);
  76.     $statement->execute();
  77.     $result = $statement->fetchAll();
  78.     $total_row = $statement->rowCount();
  79.     $output = '';
  80.     if($total_row > 0)
  81.     {
  82.         foreach($result as $row)
  83.         {
  84.             $output .= '
  85.             <div class="col-sm-3 col-lg-4 col-md-3">
  86.                 <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;">
  87.                     <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;">
  88.                         <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive">
  89.                     </audio>
  90.                     <p align="center"><strong> '. $row['voice_name'] .'</strong></p>
  91.  
  92.                     <p style="font-size: 12px;">
  93.                     Gender              : '. $row['voice_gender'].' <br />
  94.                     Genres               : '. $row['voice_genres'].' <br />
  95.                     Voice Modulation  : '. $row['voice_voice_modulation'].' <br />
  96.                     Languages          : '. $row['voice_languages'].' <br />
  97.                     Jingle Moods      : '. $row['voice_jingle_moods'].' <br />
  98.                     Ivr               : '. $row['voice_ivr'].' <br /> </p>
  99.                     <button class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;"> Add to PlayList </button>
  100.                 </div>
  101.  
  102.             </div>
  103.             ';
  104.         } 
  105.     }
  106.     else 
  107.     {
  108.         $output = '<h3>No Data Found</h3>';
  109.     }
  110.     echo $output;
  111. }
  112. ?>
How can i add add-to-cart functionality.



Note : In the cart just voice_id, voice_name, not necessary qty & price.



My current output:

Jun 10 '19 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.