![]() |
html special characters & mysql - 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: html special characters & mysql (/showthread.php?tid=28457) |
html special characters & mysql - El Forum - 03-11-2010 [eluser]NikosV[/eluser] ok.. here is my problem. i have got a functions that gets as input a keyword and searches into the database for that keyword. The problem is that when the keyword contains a special character (in my case a parenthesis) it doesn't return any results unless i have saved the characters in the database using their code For example: 0; for parenthesis. Is there a way so that i can avoid entering the code in the database? thanks in advance. html special characters & mysql - El Forum - 03-11-2010 [eluser]NikosV[/eluser] my database is utf8 if that helps. html special characters & mysql - El Forum - 03-11-2010 [eluser]kenjis[/eluser] You stored "& #40;" in database? It's a bad practice. It's better to store "(" in database. html special characters & mysql - El Forum - 03-11-2010 [eluser]NikosV[/eluser] [quote author="Kenji @ CodeIgniter Users Group in Japan" date="1268373595"]You stored "& #40;" in database? It's a bad practice. It's better to store "(" in database.[/quote] but that's exactly my problem, when i store "(" my function doesn't get any results because the query is searching for "& #40;". How can i solve that? html special characters & mysql - El Forum - 03-11-2010 [eluser]kenjis[/eluser] [quote author="NikosV" date="1268375182"][quote author="Kenji @ CodeIgniter Users Group in Japan" date="1268373595"]You stored "& #40;" in database? It's a bad practice. It's better to store "(" in database.[/quote] but that's exactly my problem, when i store "(" my function doesn't get any results because the query is searching for "& #40;". How can i solve that?[/quote] How about chaning the query from searching "& #40;" to searching "(" ? html special characters & mysql - El Forum - 03-12-2010 [eluser]NikosV[/eluser] ok maybe i didn't myself clear... while i retrieve data without special data codes from db.. when sending query are turning into special character codes... let's say i have a model function get_best_resto() is like this: Code: function get_best_resto($startRow='',$n='') in the view file i am calling the above model function and i create link to a controller function restaurant/index() giving as input the resto_name : Code: <?php so when clicking the link the following controller function is loaded which is calling a model function is_resto_exist() to check if the keyword (resto_name) exists in the database: Code: function index($keyword='') tha is_resto_exist model function is as follows: Code: function is_resto_exist($resto_name) and here is the problem: when keyword containing special characters (parenthesis in my case) cannot find it in the database. i used the CI profiler to check why is that happening, as it is the same sting that it retrieves from the database. and i realized that while it recieves the string from the database in the form "restaurant (whatever)", in the query it sends is in the form "restaurant & #40 the & #41". The problem is only solved when saving in the database the special character codes. so...can anyone tell me, what i am missing here? how can i solve this problem? html special characters & mysql - El Forum - 03-12-2010 [eluser]kenjis[/eluser] [quote author="NikosV" date="1268406200"]ok maybe i didn't myself clear... while i Code: function index($keyword='') CI converts the string in $keyword to html entity. How about below? Code: function index($keyword='') html special characters & mysql - El Forum - 03-12-2010 [eluser]NikosV[/eluser] you were right... works fine now. Thanks :-) |