Jump to content

Sql Search - space problem


Seorniyc

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/288515-sql-search-space-problem/
Share on other sites

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.

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.


  1. $S3 = sprintf("Orj_P_N like '%%%s%%'",mysql_real_escape_string($search));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.