![]() |
Mysql Custom Select - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Mysql Custom Select (/showthread.php?tid=668) |
Mysql Custom Select - nahid.tct - 01-03-2015 Dear concern, I have face a problem to make a codeigniter query from mysql query My mysql query is : select * from class_routine where semester='$semester' and day='$day' and time_schedule='$time_schedule' and (batch='$batch' or section='$section' or teacher='$teacher' or room='$room'); Please help me. Thanks Nahid RE: Mysql Custom Select - bclinton - 01-03-2015 You have a working mysql query? Use $this->db->last_query() in CodeIgniter to see if the query Codigniter is sending to the database matches the working query. RE: Mysql Custom Select - nahid.tct - 01-03-2015 I use below query: $query = $this->db->query('select * from class_routine where semester='$semester' and day='$day' and time_schedule='$time_schedule' and (batch='$batch_no' or section='$section' or teacher='$teacher' or room='$room');'); And I get this error: Parse error: syntax error, unexpected '$semester' (T_VARIABLE) in C:\xampp\htdocs\crm\application\models\m_class_routine.php on line 9 RE: Mysql Custom Select - Jamie - 01-04-2015 (01-03-2015, 10:34 PM)nahid.tct Wrote: I use below query: Hi Nahid.tct, Either of the following should work. In your query string you are failing to join the string data with the full stop (period) character. PHP Code: $query = $this->db->query('select * from class_routine where semester='.$semester.' and day='.$day.' and time_schedule='.$time_schedule.' and (batch='.$batch_no.' or section='.$section.' or teacher='.$teacher.' or room='.$room.');'); or PHP Code: $query = $this->db->query("select * from class_routine where semester='$semester' and day='$day' and time_schedule='$time_schedule' and (batch='$batch_no' or section='$section' or teacher='$teacher' or room='$room');"); Hope this helps ![]() You may wish to take a look at the query builder class: CI2 | CI3. Whilst your method would work it's always nice to learn a new method, eh? and it may help simplify your future database queries ![]() RE: Mysql Custom Select - nahid.tct - 01-04-2015 Thanks Jamie , I will try and let know. RE: Mysql Custom Select - InsiteFX - 01-05-2015 Open and close your query with double quotes not single quotes. RE: Mysql Custom Select - bclinton - 01-05-2015 (01-05-2015, 04:45 AM)InsiteFX Wrote: Open and close your query with double quotes not single quotes. Heh, that's the first thing I thought too, but my eyes were fooled into thinking he had double quotes. |