ajout recherche
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
1
CodeIgniter-3.1.13/application/views/error.php
Normal file
1
CodeIgniter-3.1.13/application/views/error.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php echo "<div> $page non trouvé</div>";?>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user