Database acting crazy - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Database acting crazy (/showthread.php?tid=34958) |
Database acting crazy - El Forum - 10-14-2010 [eluser]Unknown[/eluser] Hello chaps, Having a spot of bother trying to grab some data out of my database. I have the following model: Code: function GetRestaurants($options = array()) Now the following code works fine: Code: $this->load->model('Restaurants_model'); However the following does not work: Code: $this->load->model('Restaurants_model'); Even though the result of Code: str_replace('-', ' ', $this->uri->segment(2)) I have compared var_dumps of the output of the str_replace and the string itself and determined them to be identical. So why does the straight string return a result yet the string generated from the uri segment doesn't? Some kind of encoding issue? My database holds data in 'utf8_general_ci'. Thanks for any suggestions! Database acting crazy - El Forum - 10-14-2010 [eluser]tonanbarbarian[/eluser] are you sure there is not a space at the start or the end of the 2nd segment? try Code: echo '#'.str_replace('-', ' ', $this->uri->segment(2)).'#'; also you need to check exactly what query the code is producing so make this change Code: $query = $this->db->get("tblRestaurants"); You should then be able to see the exact query that was run and that might shed light on the issue. Database acting crazy - El Forum - 10-14-2010 [eluser]Unknown[/eluser] Thanks Tonon I checked the last query and it showed my query was actually using the string 'shed_5' Changed the str_replace from '-' to '_' and it's all working now. I had forgotten that the uri comes in with underscores as I had been using a hook to make dashes work as well. |