ajout recherche

This commit is contained in:
2024-05-29 10:50:49 +02:00
parent aa05e82ca5
commit 2d1b8c0a45
6 changed files with 88 additions and 3 deletions

View File

@@ -10,8 +10,18 @@ class Albums extends CI_Controller {
$this->load->helper('url');
}
public function index(){
$albums = $this->model_music->getAlbums();
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
$albums = $this->model_music->getAlbums();
}else{
$recherche=filter_input(INPUT_GET,'recherche');
$albums = $this->model_music->getSearchAlbums($recherche);
}
$this->load->view('layout/header');
if ($albums == false){
$page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']);
$this->load->view('error',['page'=>$page[count($page)-1]]);
$albums = $this->model_music->getAlbums();
}
$this->load->view('albums_list',['albums'=>$albums]);
$this->load->view('layout/footer');
}

View File

@@ -10,8 +10,18 @@ class Artistes extends CI_Controller {
$this->load->helper('url');
}
public function index(){
$artistes = $this->model_music->getArtistes();
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
$artistes = $this->model_music->getArtistes();
}else{
$recherche=filter_input(INPUT_GET,'recherche');= $this->model_music->getSearchArtistes($recherche);
$artistes = $this->model_music->getSearchArtistes($recherche);
}
$this->load->view('layout/header');
if ($artistes == false){
$page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']);
$this->load->view('error',['page'=>$page[count($page)-1]]);
$artistes = $this->model_music->getArtistes();
}
$this->load->view('artistes_list',['artistes'=>$artistes]);
$this->load->view('layout/footer');
}

View File

@@ -10,10 +10,21 @@ class Chansons extends CI_Controller {
$this->load->helper('url');
}
public function index(){
$chansons = $this->model_music->getChansons();
if ($recherche=filter_input(INPUT_GET,'recherche') == false or $recherche=filter_input(INPUT_GET,'recherche') == null){
$chansons = $this->model_music->getChansons();
}else{
$recherche=filter_input(INPUT_GET,'recherche');
$chansons = $this->model_music->getSearchChansons($recherche);
}
$this->load->view('layout/header');
if ($chansons == false){
$page = preg_split('/[\/]/',$_SERVER['HTTP_REFERER']);
$this->load->view('error',['page'=>$page[count($page)-1]]);
$chansons = $this->model_music->getChansons();
}
$this->load->view('chansons_list',['chansons'=>$chansons]);
$this->load->view('layout/footer');
}
}

View File

@@ -41,4 +41,54 @@ class Model_music extends CI_Model {
);
return $query->result();
}
public function getSearchAlbums($nom){
$query = $this->db->query(
"SELECT album.name,album.id,year,artist.name as artistName, genre.name as genreName,jpeg
FROM album
JOIN artist ON album.artistid = artist.id
JOIN genre ON genre.id = album.genreid
JOIN cover ON cover.id = album.coverid
WHERE album.name LIKE '$nom'
"
);
$query->result();
if ($query->num_rows() > 0){
return $query;
}
return $query = false;
}
public function getSearchArtistes($nom){
$query = $this->db->query(
"SELECT artist.name, artist.id
FROM artist
WHERE artist.name LIKE '$nom'
"
);
$query->result();
if ($query->num_rows() > 0){
return $query;
}
return $query = false;
}
public function getSearchChansons($nom){
$query = $this->db->query(
"SELECT song.name,song.id,album.year,album.name as albumName, artist.name as artistName, genre.name as genreName
FROM song
JOIN track ON track.songId = song.id
JOIN album ON album.id = track.albumId
JOIN artist ON album.artistid = artist.id
JOIN genre ON genre.id = album.genreid
WHERE song.name LIKE '$nom'
"
);
$query->result();
if ($query->num_rows() > 0){
return $query;
}
return $query = false;
}
}

View File

@@ -0,0 +1 @@
<?php echo "<div> $page non trouvé</div>";?>

View File

@@ -16,6 +16,9 @@
<nav>
<ul>
<li><strong>Music APP</strong></li>
<form method='GET'>
<input type='text' name='recherche' placeholder='Recherche... '>
</form>
</ul>
<ul>
<li><?=anchor('albums','Albums');?></li>