garyneedham Posted March 4, 2011 Share Posted March 4, 2011 Hi Everyone I have the following search which works fine But I only want to bring back an exact match in the Nif field for example if I want to search for 123456 I only want to bring this one back and not 12345, 1234, 12 etc etc can anyone help $sql = "SELECT * FROM Customer WHERE Nif Like '%" . mysql_escape_string($_GET['Nif']) . "%' ORDER BY Nif "; if (empty($_GET['Nif'])) $sql = "SELECT * FROM Nif WHERE 1 = 2 "; $res = mysql_query($sql); ?> Please keep all replies very simple as I am very new to this Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/ Share on other sites More sharing options...
Maq Posted March 4, 2011 Share Posted March 4, 2011 Then compare with '=' not LIKE. $Nif = mysql_escape_string($_GET['Nif']); WHERE Nif = '$Nif' Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/#findComment-1182870 Share on other sites More sharing options...
garyneedham Posted March 8, 2011 Author Share Posted March 8, 2011 Then compare with '=' not LIKE. $Nif = mysql_escape_string($_GET['Nif']); WHERE Nif = '$Nif' Hi I am still having problems with this can you please lay it out step by step for me Sorry I am a real beginner at this. Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/#findComment-1184465 Share on other sites More sharing options...
Pikachu2000 Posted March 8, 2011 Share Posted March 8, 2011 Describe your current problem, and post the relevant current code, please. Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/#findComment-1184484 Share on other sites More sharing options...
garyneedham Posted March 8, 2011 Author Share Posted March 8, 2011 I have the following search which works fine But I only want to bring back an exact match in the Nif field for example if I want to search for 123456 I only want to bring this one back and not 12345, 1234, 12 etc etc can anyone help $sql = "SELECT * FROM Customer WHERE Nif Like '%" . mysql_escape_string($_GET['Nif']) . "%' ORDER BY Nif "; if (empty($_GET['Nif'])) $sql = "SELECT * FROM Nif WHERE 1 = 2 "; $res = mysql_query($sql); ?> Please keep all replies very simple as I am very new to this Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/#findComment-1184488 Share on other sites More sharing options...
Pikachu2000 Posted March 8, 2011 Share Posted March 8, 2011 Replace LIKE with an = sign and remove the % sign. Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/#findComment-1184494 Share on other sites More sharing options...
garyneedham Posted March 8, 2011 Author Share Posted March 8, 2011 Thanks very much worked perfect Link to comment https://forums.phpfreaks.com/topic/229590-sql-search/#findComment-1184500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.