johnsmith153 Posted March 30, 2009 Share Posted March 30, 2009 I believe this is standard for SQL queries: $sql = sprintf("SELECT Name FROM $tableName WHERE Name LIKE '%s'",mysql_real_escape_string($name)); However, I want to do this: $sql = "SELECT Name FROM $tableName WHERE Name LIKE '%$name%'"; i.e I want to search the table and return values that contain the $name (as opposed to the first one which only returns exact matches). How would I do the sprintf code that also includes the ability to search part of a value (ie the % before and after the value)? Quote Link to comment https://forums.phpfreaks.com/topic/151785-simple-sql-query-if-you-know-much-about-sql-anyway/ Share on other sites More sharing options...
wildteen88 Posted March 30, 2009 Share Posted March 30, 2009 $sql = sprintf("SELECT Name FROM %s WHERE Name LIKE '%%%s%%'", $tableName, mysql_real_escape_string($name)); Quote Link to comment https://forums.phpfreaks.com/topic/151785-simple-sql-query-if-you-know-much-about-sql-anyway/#findComment-797010 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.