2024-05-22 23:26:06 +02:00
< ? php
defined ( 'BASEPATH' ) OR exit ( 'No direct script access allowed' );
class Search_model extends CI_Model {
public function __construct (){
parent :: __construct ();
$this -> load -> database ();
}
public function searchMusiques ( $query ){
$sql = " SELECT song.id, song.name, artist.id as artist_id, artist.name as artistName, album.name as album_name, track.albumid as album_id, cover.jpeg as cover
FROM song
JOIN track ON song . id = track . songid
JOIN album ON track . albumid = album . id
JOIN artist ON album . artistid = artist . id
JOIN cover ON album . coverid = cover . id
2024-05-23 09:59:04 +02:00
WHERE song . name LIKE ?
2024-05-22 23:26:06 +02:00
ORDER BY song . name ASC " ;
2024-05-23 09:59:04 +02:00
$query = $this -> db -> query ( $sql , array ( '%' . $query . '%' ));
2024-05-22 23:26:06 +02:00
return $query -> result ();
}
public function searchAlbums ( $query ){
2024-05-30 14:11:04 +02:00
$sql = " SELECT album.id, album.name, album.year, artist.id as artist_id, artist.name as artistName, genre.name as genreName, cover.jpeg
2024-05-22 23:26:06 +02:00
FROM album
JOIN artist ON album . artistid = artist . id
JOIN genre ON album . genreid = genre . id
JOIN cover ON album . coverid = cover . id
2024-05-23 09:59:04 +02:00
WHERE album . name LIKE ?
2024-05-22 23:26:06 +02:00
ORDER BY album . name ASC " ;
2024-05-23 09:59:04 +02:00
$query = $this -> db -> query ( $sql , array ( '%' . $query . '%' ));
2024-05-22 23:26:06 +02:00
return $query -> result ();
}
2024-05-30 14:11:04 +02:00
2024-05-22 23:26:06 +02:00
public function searchGenres ( $query ){
2024-05-23 09:59:04 +02:00
$sql = " SELECT id, name FROM genre WHERE name LIKE ? ORDER BY name ASC " ;
$query = $this -> db -> query ( $sql , array ( '%' . $query . '%' ));
2024-05-22 23:26:06 +02:00
return $query -> result ();
}
public function searchArtistes ( $query ){
2024-05-23 09:59:04 +02:00
$sql = " SELECT id, name FROM artist WHERE name LIKE ? ORDER BY name ASC " ;
$query = $this -> db -> query ( $sql , array ( '%' . $query . '%' ));
2024-05-22 23:26:06 +02:00
return $query -> result ();
}
}
2024-05-30 14:11:04 +02:00
?>