Seorniyc Posted May 15, 2014 Share Posted May 15, 2014 (edited) Hi ;I have problem with search script ;This is code ; $search_form = "<form method='get' action='' ><span class='aktif'>Arama</span><input class='aktif' type='text' name='search' ><input class='aktif' type='submit'></form>"; echo $search_form ; $search = isset($_GET['search']) ? trim($_GET['search']): ''; $a1=(str_replace(' ', '',$search) ); $S1 = ' '; $S2 = ' '; $S3 = ' '; if($search != ''){ // Terimlerin Arama Kısmı $S1 = sprintf("WHERE Tetik_Ref like '%%%s%%' OR ",mysql_real_escape_string($search)); $S2 = sprintf("Marka_Model like '%%%s%%' OR",mysql_real_escape_string($search)); $S3 = sprintf("Orj_P_N like '%%%s%%'",mysql_real_escape_string($search)); } //Verilerin yazdırılma işlemi $main_query = "SELECT * FROM ats_motor $S1 $S2 $S3 "; $count_query = "SELECT COUNT(*) FROM ats_motor $S1 $S2 $S3 "; Orj_P_N column inside Original Part Numbers. Its same of "111 11 111" or "15K 1245 45" etc. When i search exact records work fine. But I search 11111111 nothing found. I search that and find str_replace function. But i cant use that. Cant import. I try change line 8 and 14. it give me error. Can anybody help me ?Thanks. Edited May 15, 2014 by Seorniyc Quote Link to comment https://forums.phpfreaks.com/topic/288515-sql-search-space-problem/ Share on other sites More sharing options...
ginerjm Posted May 15, 2014 Share Posted May 15, 2014 How about skipping the sprintf calls to build your query and just create the string you need? Nothing magic about sprintf and it just complicates things. Then - echo out the query statement before you run it so we can what has been built. Be sure you have error checking turned on in your php and ALWAYS check the result of the query call to be sure it ran. Quote Link to comment https://forums.phpfreaks.com/topic/288515-sql-search-space-problem/#findComment-1479627 Share on other sites More sharing options...
Jacques1 Posted May 15, 2014 Share Posted May 15, 2014 Hi, I don't see you using $a1 anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/288515-sql-search-space-problem/#findComment-1479628 Share on other sites More sharing options...
Seorniyc Posted May 16, 2014 Author Share Posted May 16, 2014 Thanks for reply ;Dear Ginerjm ; Im newbie on php. I try build myself but always missing something. Then i search my mistakes i found this code. I add multiple search conditions , change it for my needs. Now only need str_replace for spaces.. Dear Jacques1; I add a1 define for try. But i cant use a1 on $s3 line. search work with '%%%s%%' , i change that to a1 that give error on this line. $S3 = sprintf("Orj_P_N like '%%%s%%'",mysql_real_escape_string($search)); Quote Link to comment https://forums.phpfreaks.com/topic/288515-sql-search-space-problem/#findComment-1479663 Share on other sites More sharing options...
ginerjm Posted May 16, 2014 Share Posted May 16, 2014 Well, you'll never LEARN by just copying someone else's bad code. The sooner you start READING up on php and WRITING your own code the SMARTER you'll be. Good luck in your endeavors - and on this course, they will definitely be endeavors. Quote Link to comment https://forums.phpfreaks.com/topic/288515-sql-search-space-problem/#findComment-1479696 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.