SAE_2.02/CodeIgniter-3.1.13/application/models/Search_model.php

50 lines
1.8 KiB
PHP
Raw Normal View History

<?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
WHERE song.name LIKE '%$query%'
ORDER BY song.name ASC";
$query = $this->db->query($sql);
return $query->result();
}
public function searchAlbums($query){
$sql = "SELECT album.id, album.name, album.year, artist.name as artistName, genre.name as genreName, cover.jpeg
FROM album
JOIN artist ON album.artistid = artist.id
JOIN genre ON album.genreid = genre.id
JOIN cover ON album.coverid = cover.id
WHERE album.name LIKE '%$query%'
ORDER BY album.name ASC";
$query = $this->db->query($sql);
return $query->result();
}
public function searchGenres($query){
$sql = "SELECT id, name FROM genre WHERE name LIKE '%$query%' ORDER BY name ASC";
$query = $this->db->query($sql);
return $query->result();
}
public function searchArtistes($query){
$sql = "SELECT id, name FROM artist WHERE name LIKE '%$query%' ORDER BY name ASC";
$query = $this->db->query($sql);
return $query->result();
}
}