Jump to content

aveeva

Members
  • Content Count

    54
  • Joined

  • Last visited

Community Reputation

0 Neutral

About aveeva

  • Rank
    Regular Member
  1. help me with my workout : my_cart.php: <?php header('Content-Type: text/html; charset=utf-8'); session_start(); session_regenerate_id(); echo ' <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <metaname="viewport"content="width=device-width,height=device-height,initial-scale=1"> <title>Playlist</title> </head> <body> <form id="playlist" action="playlist_action.php" method="post"> <table id="playlist"> <caption>Play List</caption> <thead> <tr> <th scope="col">Voice SKU</th> <th scope="col">Voice Name</th> <th scope="col">Action</th> </tr> </thead> <tbody>'; foreach ($_SESSION['playlist'] as $key => $value) { $key = htmlspecialchars($key); echo ' <tr> <th scope="row">', $key, '</th> <td>', htmlspecialchars($value), '</td> <td><button name="delete" value="', $key, '">Delete</button></td> </tr>'; } echo ' </tbody> </table> </form> </body> </html> playlist_action.php <?php header('Content-Type: text/html; charset=utf-8'); session_start(); session_regenerate_id(); if (array_key_exists('playlist_action', $_POST)) { switch ($_POST['playlist_action']) { case 'delete': if (array_key_exists($_POST['delete'], $_SESSION['playlist']) { unset($_SESSION['playlist'][$_POST['delete']]); // notify user of successful delete } else { // notify user of non-existent key in the playlist } default: // handle invalid/unknown action here. } } ?> my output: |Parse error: syntax error, unexpected 'unset' (T_UNSET) in C:\wamp\www\voice_bank\playlist_action.php on line *10*|
  2. @Barand Did you mean -> document.getElementById('$key').remove(); ?
  3. @Barand If i click delete button whole list will be deleted, how to delete by single, <html> <head> <style type="text/css"> table { border-collapse: collapse; border: 1px solid black; } table td,th { border: 1px solid black; } td { text-align: center; } </style> </head> <body> <h2>Play Lists</h2> <table id="table"> <th>Voice SKU</th> <th>Voice Name</th> <th>Action</th> <?php session_start(); foreach ($_SESSION['playlist'] as $key => $value) { echo "<tr>"; echo "<td>" . $key . "</td>\n<td>" . $value . "</td>"; echo "<td>". "<button id='btn'>Delete</button>"."</td>"; echo "</tr>"; } ?> </table> <script> var btn = document.getElementById('btn'); btn.onclick = function () { document.getElementById('table').remove(); this.remove(); }; </script> </body> </html>
  4. @Barand If i ask any stupid question, make me a pardon, i am learning in php. <?php session_start(); foreach ($_SESSION['playlist'] as $key => $value) { echo "<tr>"; echo "<td>" . $key . "</td>\n<td>" . $value . "</td>"; echo "<td>" ."<button class='delbtn' data-id='"+ k +"'>Delete</button>" . "<td>"; echo "</tr>"; } ?> Pls correct me?
  5. @Barand That line okay, i got it, no confusion. My confusion about how can i use in below code, <?php session_start(); foreach ($_SESSION['playlist'] as $key => $value) { echo "<tr>"; echo "<td>" . $key . "</td>\n<td>" . $value . "</td>"; // code.... echo "</tr>"; } ?>
  6. @Barand For my clarification, this line -> "<td><button class='delbtn' data-id='"+ k +"'>Delete</button></td>"
  7. @Barand I just want to show playlist to other page, so i create view_cart.php : <html> <head> <style type="text/css"> table { border-collapse: collapse; border: 1px solid black; } table td,th { border: 1px solid black; } td { text-align: center; } </style> </head> <body> <h2>Play Lists</h2> <table> <th>Voice SKU</th> <th>Voice Name</th> <?php session_start(); foreach ($_SESSION['playlist'] as $key => $value) { echo "<tr>"; echo "<td>" . $key . "</td>\n<td>" . $value . "</td>"; echo "</tr>"; } ?> </table> </body> </html> I have passed both voice_sku and voice_name to view_cart.php, here how can i pass along with delete option. Output:
  8. Finally working after changes the value sku to voice_sku and name to voice_name in JS.
  9. @Barand FYI -> here i changed my_cart.php to manage_cart.php & voice_id to voice_sku Main PHP file, <?php session_start(); if (isset($_SESSION['playlist'])) { echo '<pre>', print_r($_SESSION['playlist'], 1), '</pre>'; echo "</hr><br>\n"; } include('database_connection.php'); // start Custom filter if(isset($_POST["action"])) { $query = " SELECT * FROM voice_bank_data WHERE voice_status = '1' "; // Gender if(isset($_POST["gender"])) { $gender_filter = implode("','", $_POST["gender"]); $query .= " AND voice_gender IN('".$gender_filter."') "; } // Genres if(isset($_POST["genres"])) { $genres_filter = implode("','", $_POST["genres"]); $query .= " AND voice_genres IN('".$genres_filter."') "; } // Voice Modulation if(isset($_POST["voice_modulation"])) { $voice_modulation_filter = implode("','", $_POST["voice_modulation"]); $query .= " AND voice_voice_modulation IN('".$voice_modulation_filter."') "; } // Languages if(isset($_POST["languages"])) { $languages_filter = implode("','", $_POST["languages"]); $query .= " AND voice_languages IN('".$languages_filter."') "; } // Jingle Moods if(isset($_POST["jingle_moods"])) { $jingle_moods_filter = implode("','", $_POST["jingle_moods"]); $query .= " AND voice_jingle_moods IN('".$jingle_moods_filter."') "; } // IVR if(isset($_POST["ivr"])) { $ivr_filter = implode("','", $_POST["ivr"]); $query .= " AND voice_ivr IN('".$ivr_filter."') "; } // end Custom filter $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $total_row = $statement->rowCount(); $output = ''; if($total_row > 0) { foreach($result as $row) { $output .= ' <div class="col-sm-3 col-lg-4 col-md-3"> <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;"> <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;"> <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive"> </audio> <p align="center"><strong> '. $row['voice_name'] .'</strong></p> <p style="font-size: 12px;"> Voice Sku : '. $row['voice_sku'].' <br /> voice Name : '. $row['voice_name'].' <br /> Gender : '. $row['voice_gender'].' <br /> Genres : '. $row['voice_genres'].' <br /> Voice Modulation : '. $row['voice_voice_modulation'].' <br /> Languages : '. $row['voice_languages'].' <br /> Jingle Moods : '. $row['voice_jingle_moods'].' <br /> Ivr : '. $row['voice_ivr'].' <br /> </p> <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-voice_sku="'.$row["voice_sku"].'" data-voice_name="'.$row["voice_name"].'">Add to Playlist</button> </div> </div> '; } } else { $output = '<h3>No Data Found</h3>'; } echo $output; } ?> <html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $().ready( function() { $(".btn").click( function() { var vid = $(this).data("sku"); var vname = $(this).data("name"); $.post( "manage_cart.php", { "voice_sku" : vid, "voice_name" : vname, "action" : "Add" }, function(resp) { outputPlaylist(resp) }, "JSON" ) }) function outputPlaylist(resp) { var list = "<tr><td><b>ID</b></td><td><b>Title</b></td></tr>\n"; $.each(resp, function(k, v) { list = list + "<tr><td>" + k + "</td><td>" + v + "</td>" list = list + "<td><button class='delbtn' data-id='"+ k +"'>Delete</button></td></tr>\n" // add "Delete" button to each playlist item }) $("#playlist").html(list) // define action for new delbtn's $(".delbtn").click( function() { var vid = $(this).data("sku"); $.post( "manage_cart.php", { "voice_sku" : vid, "action" : "Delete"}, function(resp) { outputPlaylist(resp) }, "JSON" ) }) } }) </script> </head> <body> <h2>Playlists...</h2> <table style="width:600px" id="playlist"> </table> </body> </html> manage_cart.php (prior - my_cart.php) <?php session_start(); if ($_SERVER['REQUEST_METHOD']=='POST') { $voice_sku = $_POST['$voice_sku'] ?? 0; $action = $_POST['action'] ?? ''; if ($action == 'Delete') { // we are deleting the item from the session array if ($voice_sku) { unset($_SESSION['playlist'][$voice_sku]); exit(json_encode($_SESSION['playlist'])) ; } } elseif ($action == 'Add') { // we are adding the item $voice_name = $_POST['voice_name'] ?? ''; if ($voice_sku && $voice_name) { $_SESSION['playlist'][$voice_sku] = $voice_name; exit(json_encode($_SESSION['playlist'])) ; } } else { exit("ERROR") ; } } exit("ERROR") ; ?> Expected output : added to playlists actual output : Not added to playlist output : How to solve the error?
  10. @Barand How to delete individual row like -> https://jsfiddle.net/annoyingmouse/7c0v1ra3/
  11. *Finally done, sorry for lots of reply, i can't able to delete.
  12. How can i use my $output .= ' <div class="col-sm-3 col-lg-4 col-md-3"> <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;"> <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;"> <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive"> </audio> <p align="center"><strong> '. $row['voice_name'] .'</strong></p> <p style="font-size: 12px;"> Voice Sku : '. $row['voice_sku'].' <br /> voice Name : '. $row['voice_name'].' <br /> Gender : '. $row['voice_gender'].' <br /> Genres : '. $row['voice_genres'].' <br /> Voice Modulation : '. $row['voice_voice_modulation'].' <br /> Languages : '. $row['voice_languages'].' <br /> Jingle Moods : '. $row['voice_jingle_moods'].' <br /> Ivr : '. $row['voice_ivr'].' <br /> </p> <button type="button" class="btn btn-primary" style="padding: 5px 83px 5px 83px;" data-voice-sku="'.$row["voice_sku"].'" data-voice-name="'.$row["voice_name"].'">Add to Playlist</button> </div> </div> '; instead of, <body> Song 1 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="1" data-name="song-1.mp3">Add to PlayList </button> <br> Song 2 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="2" data-name="song-2.mp3">Add to PlayList </button> <br> Song 3 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="3" data-name="song-3.mp3">Add to PlayList </button> <br> Song 4 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="4" data-name="song-4.mp3">Add to PlayList </button> <br> Song 5 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="5" data-name="song-5.mp3">Add to PlayList </button> <br> Song 6 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="6" data-name="song-6.mp3">Add to PlayList </button> <br> <br> <h2>Playlist</h2> <table style="width:600px" id="playlist"> </table> </body>
  13. FYI -> Neglect last reply, here is my complete code : fetch_data.php <?php session_start(); if (isset($_SESSION['playlist'])) { echo '<pre>', print_r($_SESSION['playlist'], 1), '</pre>'; echo "</hr><br>\n"; } //fetch_data.php include('database_connection.php'); if(isset($_POST["action"])) { $query = " SELECT * FROM voice_bank_data WHERE voice_status = '1' "; // if(isset($_POST["minimum_price"], $_POST["maximum_price"]) && !empty($_POST["minimum_price"]) && !empty($_POST["maximum_price"])) // { // $query .= " // AND product_price BETWEEN '".$_POST["minimum_price"]."' AND '".$_POST["maximum_price"]."' // "; // } // Gender if(isset($_POST["gender"])) { $gender_filter = implode("','", $_POST["gender"]); $query .= " AND voice_gender IN('".$gender_filter."') "; } // Genres if(isset($_POST["genres"])) { $genres_filter = implode("','", $_POST["genres"]); $query .= " AND voice_genres IN('".$genres_filter."') "; } // Voice Modulation if(isset($_POST["voice_modulation"])) { $voice_modulation_filter = implode("','", $_POST["voice_modulation"]); $query .= " AND voice_voice_modulation IN('".$voice_modulation_filter."') "; } // Languages if(isset($_POST["languages"])) { $languages_filter = implode("','", $_POST["languages"]); $query .= " AND voice_languages IN('".$languages_filter."') "; } // Jingle Moods if(isset($_POST["jingle_moods"])) { $jingle_moods_filter = implode("','", $_POST["jingle_moods"]); $query .= " AND voice_jingle_moods IN('".$jingle_moods_filter."') "; } // IVR if(isset($_POST["ivr"])) { $ivr_filter = implode("','", $_POST["ivr"]); $query .= " AND voice_ivr IN('".$ivr_filter."') "; } $statement = $connect->prepare($query); $statement->execute(); $result = $statement->fetchAll(); $total_row = $statement->rowCount(); $output = ''; if($total_row > 0) { foreach($result as $row) { $output .= ' <div class="col-sm-3 col-lg-4 col-md-3"> <div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:300px;"> <audio controls controlsList="nodownload" style="padding: 10px 10px 10px 10px;margin-left: -21px;"> <source src="audio_sample/'. $row['voice_audio_file'] .'" alt="" class="img-responsive"> </audio> <p align="center"><strong> '. $row['voice_name'] .'</strong></p> <p style="font-size: 12px;"> Voice Sku : '. $row['voice_sku'].' <br /> voice Name : '. $row['voice_name'].' <br /> Gender : '. $row['voice_gender'].' <br /> Genres : '. $row['voice_genres'].' <br /> Voice Modulation : '. $row['voice_voice_modulation'].' <br /> Languages : '. $row['voice_languages'].' <br /> Jingle Moods : '. $row['voice_jingle_moods'].' <br /> Ivr : '. $row['voice_ivr'].' <br /> </p> <button type="button" class="btn btn-primary" style="padding: 5px 83px 5px 83px;" data-voice-sku="'.$row["voice_sku"].'" data-voice-name="'.$row["voice_name"].'">Add to Playlist</button> </div> </div> '; } } else { $output = '<h3>No Data Found</h3>'; } echo $output; } ?> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $().ready( function() { $(".btn").click( function() { var vid = $(this).data("id"); var vname = $(this).data("name"); $.post( "my_cart.php", { "voice_id" : vid, "voice_name" : vname}, function(resp) { var list = "<tr><td><b>ID</b></td><td><b>Title</b></td></tr>\n"; $.each(resp, function(k, v) { list = list + "<tr><td>" + k + "</td><td>" + v + "</td></tr>\n" }) $("#playlist").html(list) }, "JSON" ) }) }) </script> </head> <body> Song 1 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="1" data-name="song-1.mp3">Add to PlayList </button> <br> Song 2 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="2" data-name="song-2.mp3">Add to PlayList </button> <br> Song 3 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="3" data-name="song-3.mp3">Add to PlayList </button> <br> Song 4 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="4" data-name="song-4.mp3">Add to PlayList </button> <br> Song 5 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="5" data-name="song-5.mp3">Add to PlayList </button> <br> Song 6 <button type="button" class="btn btn-primary" type="submit" style="padding: 5px 83px 5px 83px;" data-id="6" data-name="song-6.mp3">Add to PlayList </button> <br> <br> <h2>Playlist</h2> <table style="width:600px" id="playlist"> </table> </body> </html> My_cart.php <?php session_start(); if ($_SERVER['REQUEST_METHOD']=='POST') { $voice_id = $_POST['voice_id'] ?? 0; $voice_name = $_POST['voice_name'] ?? ''; if ($voice_id && $voice_name) { $_SESSION['playlist'][$voice_id] = $voice_name; exit(json_encode($_SESSION['playlist'])) ; } } exit("ERROR") ; ?> output is ERROR.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.