CodeIgniter Forums
querry question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: querry question (/showthread.php?tid=40251)



querry question - El Forum - 04-03-2011

[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!


querry question - El Forum - 04-03-2011

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

InsiteFX


querry question - El Forum - 04-03-2011

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


querry question - El Forum - 04-03-2011

[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


querry question - El Forum - 04-03-2011

[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


querry question - El Forum - 04-04-2011

[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;
}