delete song

This commit is contained in:
Julian GALLEGO 2024-06-05 17:38:12 +02:00
parent 9d492207b0
commit 8b0ec23975
3 changed files with 24 additions and 4 deletions

View File

@ -24,9 +24,15 @@ class Playlist extends CI_Controller {
public function SongPlaylist($playlist_id){ public function SongPlaylist($playlist_id){
$songPlaylists = $this->model_music->getSongOfPlaylist($playlist_id); $songPlaylists = $this->model_music->getSongOfPlaylist($playlist_id);
//$this->load->view('layout/header_album'); $playlists = $this->model_music->getPlaylist(); // Récupère toutes les playlists
$this->load->view('song_playlist', ['songPlaylists' => $songPlaylists]); $id_playlist = null; // Initialise $id_playlist à null
//$this->load->view('layout/footer_album'); 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) { public function delete($playlist_id) {
@ -34,6 +40,11 @@ class Playlist extends CI_Controller {
redirect('playlist'); 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() { public function MenuCreate() {
$this->load->view('layout/header'); $this->load->view('layout/header');
$this->load->view('create_playlist'); $this->load->view('create_playlist');

View File

@ -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){ public function createPlaylist($name_playlist){
$playlist_id = mt_rand(1, 10);
$name_playlist_escaped = $this->db->escape($name_playlist); $name_playlist_escaped = $this->db->escape($name_playlist);
$query = $this->db->query( $query = $this->db->query(
"INSERT INTO playlist (name) VALUES ($name_playlist_escaped); "INSERT INTO playlist (name) VALUES ($name_playlist_escaped);

View File

@ -4,7 +4,10 @@
foreach($songPlaylists as $songPlaylist){ foreach($songPlaylists as $songPlaylist){
echo "<div><article>"; echo "<div><article>";
echo "<header class='short-text'>"; echo "<header class='short-text'>";
echo "<form action='" . base_url("index.php/Playlist/deleteSong/{$id_playlist -> id}/{$songPlaylist-> name}") . "' method='post'>";
echo "{$songPlaylist->name}"; echo "{$songPlaylist->name}";
echo "<button type='submit' class='delete-button'>Delete</button>";
echo "</form>";
echo "<br>"; echo "<br>";
echo "</header>"; echo "</header>";
echo "</article></div>"; echo "</article></div>";