erdomester Posted May 21, 2009 Share Posted May 21, 2009 Hello, I have a statement like this: $sql_s = "SHOW TABLES FROM bkv45 WHERE Tables_in_bkv45 LIKE '%$search%' "; I have tables like this: B15_MW_something B36_MWS_anything B156_MW_notinteresting ....etc. Let's say $search=B15. The result of the query will be two tables: B15_something and B156_notinteresting. BUT i only wan't B15_something. How am i supposed to do that? I have tried LIKE '%$search%_' ->> error LIKE '%$search_%' ->> does nothing. Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/ Share on other sites More sharing options...
erdomester Posted May 21, 2009 Author Share Posted May 21, 2009 Neither this worked: $blabla = $search."_"; Tables_in_bkv45 LIKE '%$ize%' Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/#findComment-838954 Share on other sites More sharing options...
erdomester Posted May 21, 2009 Author Share Posted May 21, 2009 Neither this worked: $blabla = $search."_"; Tables_in_bkv45 LIKE '%$ize%' Not ize:) Tables_in_bkv45 LIKE '%$blabla%' Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/#findComment-839234 Share on other sites More sharing options...
BobcatM Posted May 21, 2009 Share Posted May 21, 2009 Click Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/#findComment-839241 Share on other sites More sharing options...
radi8 Posted May 21, 2009 Share Posted May 21, 2009 SQL is a ligical search engine and the wild cards you are using will return anything that pattern matches what was input. If you do not want the B156_ tables, then with the B15 input, add the '_' to the string literal: $blabla=$search.'_'; Then the $sql= ... WHERE Tables_in_bkv45 LIKE '$blabla%' "; will retrieve only tables that have strin patterns of B15_xxxxx. Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/#findComment-839256 Share on other sites More sharing options...
erdomester Posted May 21, 2009 Author Share Posted May 21, 2009 NOT SOLVED!!!! I accidentally clicked on the button. So. Not working what u suggest. Not working either: CONCAT('%', $search, '_', '%') This results in an error: Error in query: SHOW TABLES FROM bkv45 WHERE Tables_in_bkv45 LIKE CONCAT('%', b206, '_', '%') Unknown column 'b206' in 'where clause' (b206 is the first table in the solution, nothing wrong with it, the code just somehow goes wrong) either this: LIKE '%".$search."_%' or this: LIKE CONCAT('%', '$search', '_', '%') Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/#findComment-839263 Share on other sites More sharing options...
erdomester Posted May 21, 2009 Author Share Posted May 21, 2009 Solution: Instead of "_" i had to write "\_" Bye, erdomester Link to comment https://forums.phpfreaks.com/topic/159079-solved-php-mysql-query-with-variable/#findComment-839481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.