cottonbuds2005 Posted November 4, 2009 Share Posted November 4, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/ Share on other sites More sharing options...
ngreenwood6 Posted November 4, 2009 Share Posted November 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-950696 Share on other sites More sharing options...
cottonbuds2005 Posted November 4, 2009 Author Share Posted November 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-950701 Share on other sites More sharing options...
ngreenwood6 Posted November 4, 2009 Share Posted November 4, 2009 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-950714 Share on other sites More sharing options...
cottonbuds2005 Posted November 4, 2009 Author Share Posted November 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-950753 Share on other sites More sharing options...
xtopolis Posted November 4, 2009 Share Posted November 4, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-950757 Share on other sites More sharing options...
cottonbuds2005 Posted November 4, 2009 Author Share Posted November 4, 2009 dear xtopolis and ngreenwood6, you both did it. the results come out as they should. thanks a million for your help I love this forum and all the helpful people in it thanks Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-950761 Share on other sites More sharing options...
ngreenwood6 Posted November 4, 2009 Share Posted November 4, 2009 oh yeah sorry if you used the second one it should have been $query_SearchSerial = "SELECT * FROM assetsdb WHERE SerialNo LIKE '%$colname_SearchSerial%'"; Quote Link to comment https://forums.phpfreaks.com/topic/180219-solved-pls-help-php-search-question/#findComment-951029 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.