Hood15 Posted March 8, 2011 Share Posted March 8, 2011 I'm working on a script that when you submit the form it returns what group you'd be assigned to based on email. the database table groups has a field called "strings" and we have saved for example @gmail.com and any email containing @gmail.com will be assigned to G Mail Users. I'm having a hard time establishing how I want to do this. The one way I know I can do it is by fetching all the fields and then matching it up using stristr. I was thinking there has to be a better way using the mysql functions. Quote Link to comment https://forums.phpfreaks.com/topic/229949-db-search/ Share on other sites More sharing options...
HuggieBear Posted March 8, 2011 Share Posted March 8, 2011 Can't this be done by just using mysql's like? Obviously this isn't a complete script and you'll need to take the bits and plug them into your script. // Initial email (Obviously passed into your script via $_POST) $email = 'user@gmail.com'; // Get the domain part of the email address $domain = substr($email, strpos($email, '@')+1); // Stick it in a query to the database $sql = "SELECT group_name FROM groups WHERE string LIKE '%" . $domain . "%';" // Run a while loop on the returned results and you should be fine Quote Link to comment https://forums.phpfreaks.com/topic/229949-db-search/#findComment-1184407 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.