From 8b0ec2397573c9c7c1d56a2a92ae586d74fc0c74 Mon Sep 17 00:00:00 2001 From: gallego Date: Wed, 5 Jun 2024 17:38:12 +0200 Subject: [PATCH] delete song --- ci/application/controllers/Playlist.php | 17 ++++++++++++++--- ci/application/models/Model_music.php | 8 +++++++- ci/application/views/song_playlist.php | 3 +++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ci/application/controllers/Playlist.php b/ci/application/controllers/Playlist.php index e774b21..967266c 100644 --- a/ci/application/controllers/Playlist.php +++ b/ci/application/controllers/Playlist.php @@ -24,9 +24,15 @@ class Playlist extends CI_Controller { public function SongPlaylist($playlist_id){ $songPlaylists = $this->model_music->getSongOfPlaylist($playlist_id); - //$this->load->view('layout/header_album'); - $this->load->view('song_playlist', ['songPlaylists' => $songPlaylists]); - //$this->load->view('layout/footer_album'); + $playlists = $this->model_music->getPlaylist(); // Récupère toutes les playlists + $id_playlist = null; // Initialise $id_playlist à null + foreach ($playlists as $playlist_item) { + if ($playlist_item->id == $playlist_id) { + $id_playlist = $playlist_item; + break; + } + } + $this->load->view('song_playlist', ['songPlaylists' => $songPlaylists, 'id_playlist' => $id_playlist]); } public function delete($playlist_id) { @@ -34,6 +40,11 @@ class Playlist extends CI_Controller { redirect('playlist'); } + public function deleteSong($id_playlist, $Song_name){ + $deleteSong = $this->model_music->delete_Song($id_playlist, $Song_name); + redirect("playlist/SongPlaylist/$id_playlist"); + } + public function MenuCreate() { $this->load->view('layout/header'); $this->load->view('create_playlist'); diff --git a/ci/application/models/Model_music.php b/ci/application/models/Model_music.php index 1011843..0ab9208 100644 --- a/ci/application/models/Model_music.php +++ b/ci/application/models/Model_music.php @@ -49,8 +49,14 @@ class Model_music extends CI_Model { ); } + public function delete_Song($playlist_id,$Song_name){ + $this->db->query( + "DELETE FROM SongPlaylist Where id = ? AND name LIKE ?", + array($playlist_id, $Song_name) + ); + } + public function createPlaylist($name_playlist){ - $playlist_id = mt_rand(1, 10); $name_playlist_escaped = $this->db->escape($name_playlist); $query = $this->db->query( "INSERT INTO playlist (name) VALUES ($name_playlist_escaped); diff --git a/ci/application/views/song_playlist.php b/ci/application/views/song_playlist.php index 0054f4a..d567e72 100644 --- a/ci/application/views/song_playlist.php +++ b/ci/application/views/song_playlist.php @@ -4,7 +4,10 @@ foreach($songPlaylists as $songPlaylist){ echo "
"; echo "
"; + echo "
"; echo "{$songPlaylist->name}"; + echo ""; + echo "
"; echo "
"; echo "
"; echo "
";