Jump to content

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.

Edited by Seorniyc
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));

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.