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

Link to comment
Share on other sites

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'";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.