dstoltz Posted June 29, 2010 Share Posted June 29, 2010 I have this querystring: $q = sprintf("SELECT * FROM employees WHERE fname LIKE %s OR lname LIKE %s OR badge = %s OR ssn = %s ORDER BY lname",GetSQLValueString($ename,"text"),GetSQLValueString($ename,"text"),GetSQLValueString($ebadge,"int"),GetSQLValueString($essn,"int")); Which results in: SELECT * FROM employees WHERE fname LIKE 'd' OR lname LIKE 'd' OR badge = 0 OR ssn = 0 ORDER BY lname I want to use a wildcard for the 1st two, like this: SELECT * FROM employees WHERE fname LIKE 'd%' OR lname LIKE 'd%' OR badge = 0 OR ssn = 0 ORDER BY lname How do I modify the QueryString to do this? I know I can do it in the function call like this: GetSQLValueString($ename.'%',"text") But I was thinking it would be better to do it by the %s parameter, but this doesn't work: ...WHERE fname LIKE %s\% OR ... Any ideas? Thanks! Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 29, 2010 Share Posted June 29, 2010 I guess reading the manual is too much work? To escape a type specifier withint sprintf() you use a percent character. Therefore, if you want to literally use the percent character, you would use it twice. WHERE fname LIKE %s%% OR lname LIKE %s%% But, you can't do that here. Your GetSQLValueString() functions is apparently returning the string with the value already enclosed in parens. So, you can't add the percent sign within the format string. Otherwise you would end up with: WHERE fname LIKE 'd'% OR lname LIKE 'd'% You have to add it to the value passed in the GetSQLValueString() function. Quote Link to comment Share on other sites More sharing options...
dstoltz Posted June 30, 2010 Author Share Posted June 30, 2010 Thanks for the reply.. BTW, I have been reading the manual, and web sites, and forums, trying to figure this out. Sorry I'm a PHP beginner... I didn't know this forum was only for expert level questions only... Sorry if that seems like a smart-butt response, but your comment of "reading the manual is too much work" ticked me off, considering I tried fixing this for hours. But thanks for your answer. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 30, 2010 Share Posted June 30, 2010 Sorry I'm a PHP beginner... I didn't know this forum was only for expert level questions only... No, not at all. But, the information you needed was in the manual. It was down in the comments section, but if you are spending hours researching a problem the best place to start is to fully read the manual for the particular function. With printf() and sprintf() functions, escape character is not backslash '\' but rather '%'. Sorry if I offended you, but I believe in teaching people to fish rather than giving them a fish. Quote Link to comment Share on other sites More sharing options...
dstoltz Posted July 6, 2010 Author Share Posted July 6, 2010 mjdamato, No sweat - I agree with your fishing analogy. But so you know, I was combing the manual and online sites, but for some reason this solution eluded me. Sometimes even with the answer in front of you, it's not understood. This is why I like forums, because you get a friendly explanation, rather than technical jargon. I'll try and research my questions more thoroughly before posting. Thanks Quote Link to comment 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.