Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/229949-db-search/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/229949-db-search/#findComment-1184407
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.