Welcome Guest, Not a member yet? Register   Sign In
querry question
#1

[eluser]R_Nelson[/eluser]
I have my karaoke list of songs & Artist and i have a search bar when they put in nothing or just load the page i want it do display the whole list but if they put in say JOE i want it to display all records that have joe in the song or artist. For some reason im drawing a blank on how to do this i know i have to use the WHERE and LIKE but i just can seem to remember how to put it all together. I don't care if its a CI function or the normal SELECT query just need some help remembering how to put this together!
#2

[eluser]InsiteFX[/eluser]
Please show your database tables.

InsiteFX
#3

[eluser]R_Nelson[/eluser]
id,song_name,artist
#4

[eluser]InsiteFX[/eluser]
So if JOE is an artist then it would be something like this
not sure if this will give your the output you want but try it.
Code:
function get_artist($name)
{
    $data = array();

    $this->db->where('artist', $name);
    $this->db->where('song_name', $name);

    $query = $this->db->get('table_name');

    if ($query->num_rows() > 0){
      $data = $query->row_array();
    }

    $query->free_result();
    return $data;
}

InsiteFX
#5

[eluser]R_Nelson[/eluser]
joe can be in either one in the song name or the artist i dont want to limit the search.

i will give it a try whats the worse that can happen i get an error
#6

[eluser]daniel ispas[/eluser]
If Joe can be the name of the artist or the song name you should make a small change in the code provided by InsiteFX:
Code:
function get_artist($name)
{
    $data = array();

    $this->db->where('artist', $name);
    $this->db->or_where('song_name', $name);

    $query = $this->db->get('table_name');

    if ($query->num_rows() > 0){
      $data = $query->row_array();
    }

    $query->free_result();
    return $data;
}




Theme © iAndrew 2016 - Forum software by © MyBB