playlist aléatoire
This commit is contained in:
@@ -244,4 +244,20 @@ class Model_music extends CI_Model {
|
||||
array($new_playlist_id, $playlist_id));
|
||||
}
|
||||
|
||||
public function createPlaylistRandom($name_playlist, $num_songs, $mail) {
|
||||
$data = array(
|
||||
'name' => $name_playlist,
|
||||
'mail' => $mail
|
||||
);
|
||||
$this->db->insert('playlist', $data);
|
||||
$new_playlist_id = $this->db->insert_id();
|
||||
|
||||
// Sélectionner le nombre de chansons aléatoires spécifié
|
||||
$query = $this->db->query("SELECT id, name FROM song ORDER BY RAND() LIMIT ?", array($num_songs));
|
||||
$songs = $query->result();
|
||||
|
||||
foreach ($songs as $song) {
|
||||
$this->db->query("INSERT INTO SongPlaylist (id, name) VALUES (?, ?)", array($new_playlist_id, $song->name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user