Log in

View Full Version : How does one query based on the admin email field?


Ted S
07-16-2005, 01:11 AM
I am attempting to write a script to send out emails to users automatically but I need to be sure and respect all opt-out requests (users who have unchecked "receive emails from the administrator"). Given that this field uses vbulletins binary coding system how would I run a query to see if it is selected or not on a per user basis? Thanks.

Andreas
07-16-2005, 01:19 AM
The same way you would be querieing any other bitfield too ...

SELECT username, email FROM user WHERE options & 16

give you all users who have set adminemail=yes

Ted S
07-16-2005, 03:32 AM
Thanks.

Jolten
08-27-2005, 05:21 PM
What if I want to use an if statement that states if set to receive yes if not, then no.

I don't want all users I just need to determine if one user has opted out.

(patched vb 3.0.6)

Thanks

Biker_GA
08-27-2005, 05:23 PM
If it's just one user you're wondering about, just look at the individual's info in AdminCP.

Jolten
08-27-2005, 05:24 PM
I'm automating this.... it's not that simple. I'm not stupid. Of course I know I can look.

Andreas
08-27-2005, 05:33 PM
What if I want to use an if statement that states if set to receive yes if not, then no.

I don't want all users I just need to determine if one user has opted out.

(patched vb 3.0.6)

Thanks
I don't understand that question.

Jolten
08-27-2005, 05:40 PM
I'm sending automated mail to a single user. I want a basic statement that verifies if they are set to receie admin emails. Similar to this:


if (SetToRecieveAdminEmail == 'Yes'){

mail($recipient, $subject, $message, $headers);
echo "message sent";

} else {

echo "user doesn't want mail";

}


I've already queried the user table for this single users information but I don't know how to query the bit field for this specific option setting.

If I use a where clause with the options & 16 then the query will obviously return no results if the user has opted out. This will result in no recipient. Which would mean no mail is not sent. But I'm not sure that's the best way to go about this. It seems messy.

Andreas
08-27-2005, 05:43 PM
You can can in mySQL or PHP by check verifying that options & 16 isn't 0.
If it is Zero, the Option is not set.
Where you are doing the check doesn't matter much.

Jolten
08-27-2005, 07:26 PM
Okay I sorted it by checking results. For anyone else wondering here's what I used.


$info=$DB_site->query_first("SELECT username, userid, email FROM user WHERE username = '$name' AND options &16");

if ($info == null) {

User does not want mail

} else {

send mail
]