Orionsbelter Posted September 26, 2008 Share Posted September 26, 2008 hi am making a website that then some seaches in the input box i'll search my database but i have no clue what the coding should be can anyone help, just for an easy start say i have a username search and the field is called username and the table is users. what would it look like to return all usernames like the search? thanks Link to comment https://forums.phpfreaks.com/topic/125929-search-database-script/ Share on other sites More sharing options...
Guardian-Mage Posted September 26, 2008 Share Posted September 26, 2008 SQL queries have something called like, which allow for the user of a wildcard '%'. Wildcards will match all characters, or only 1 depending on the wild card. So if you wanted to search for users with the search word anywhere in their name, you could do this: $keyword = $_POST['keyword']; //This is the value from the search box $query1 = "SELECT `username`,`id` FROM `users` WHERE `username` LIKE '%$keyword%'"; $execute1 = mysql_query($query1) or die("Oops, looks like there was an error<br /><br />" . mysql_error()); while ($i = mysql_fetch_row($execute1)) { echo $i[0] . "<br />"; } Link to comment https://forums.phpfreaks.com/topic/125929-search-database-script/#findComment-651171 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.