Jump to content

[SOLVED] Pls help, PHP search question


cottonbuds2005

Recommended Posts

Hi,

 

Im totally new to PHP and I need help with this code. It displays results only when the search is exact, like when I search serial number LV9237 in doesnt show LV9237 (2),,, etc. When I search LV923 no results come out. How do I edit the code to amend this? Thank you

 

mysql_select_db($database_ITInventory, $ITInventory);

$query_SearchSerial = sprintf("SELECT * FROM assetsdb WHERE SerialNo = %s", GetSQLValueString($colname_SearchSerial, "text"));

$SearchSerial = mysql_query($query_SearchSerial, $ITInventory) or die(mysql_error());

$row_SearchSerial = mysql_fetch_assoc($SearchSerial);

$totalRows_SearchSerial = mysql_num_rows($SearchSerial);

Link to comment
https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/
Share on other sites

change this line:

 

$query_SearchSerial = sprintf("SELECT * FROM assetsdb WHERE SerialNo = %s", GetSQLValueString($colname_SearchSerial, "text"));

 

to this:

 

$query_SearchSerial = sprintf("SELECT * FROM assetsdb WHERE SerialNo = %s%", GetSQLValueString($colname_SearchSerial, "text"));

 

All i did there was add a % at the end of the s.

Hi ngreenwood6,

 

Thanks for the reply. I did what you suggested but I got this:

 

Warning: sprintf() [function.sprintf]: Too few arguments in C:\wamp\www\ITInventoryApplication\ITInventory\files\Search.php on line 77

Query was empty

 

im stumped. thank you again

sorry its been a long day it should be:

 

$query_SearchSerial = sprintf("SELECT * FROM assetsdb WHERE SerialNo LIKE %s", GetSQLValueString($colname_SearchSerial, "text"));

 

Like does a match upon it. I dont know why you are doing the query like that you can simply do:

 

$query_SearchSerial = "SELECT * FROM assetsdb WHERE SerialNo LIKE '$colname_SearchSerial'";

No problem at all, really appreciate you helping me a newbie like me

I tried your idea but the results are pretty much the same, i still have to input the exact word to get results

i have series of machine serial numbers starting with lvw, i wish i could type "lvw to get multiple results

but i still need to type the whole word to get it........... im sorry

 

and thanks again, still hoping to get help out there

Wouldn't ngreenwood6's suggestion be

$query_SearchSerial = "SELECT * FROM assetsdb WHERE SerialNo LIKE '" . $colname_SearchSerial . "%'";

so that it searches for things beginning with $colname_SearchSerial  The way he has it, it looks for exact matches...

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.