PDA

View Full Version : I need some help with this if/else statement


Parker Clack
22 Mar 2002, 00:15
I have added the option in the User Control Panel to select whether or not you want an email response each time some one replies to a thread you have requested email notifications on or just the one time (as is vBulletin's default).

I have added a row to the User table called allemail and then
in the email notification section of the functions.php file I added

if ($bbuserinfo['allemail']==0) {
$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'
AND user.lastactivity>'$lastposttime[dateline]'");
} else {

$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'");
}

When they select "No" the value is zero and they should just get one response. If "Yes" they should get a response each time. As
it is working now though they get a response each time. So it appears to me that the if statement isn't working and it just defaults to the last statement. Allemail is getting set to 1 or 0 just fine from the user control panel but the script does not appear to recognize the if else routine.

Any ideas on how to get this to work?

Thanks,
Parker

Mark Hensler
22 Mar 2002, 06:35
simple debuging skills... "When in doubt, print it out." ;)

print the value of $bbuserinfo['allemail']

Parker Clack
22 Mar 2002, 10:11
Mark:

Sorry, I am not the great of a coder. How would I go about printing this out?

Parker

Chen
22 Mar 2002, 12:24
Is $bbuserinfo available in that function?

Parker Clack
22 Mar 2002, 14:18
Chen:

It should be. Here is a bit more of the code in question as I have it written into the existing code.

....$lastposttime=$DB_site->query_first("SELECT dateline
FROM post
WHERE threadid='$threadid'
ORDER BY dateline DESC
LIMIT ".iif($moderated, '1,1', '1'));
// if it's moderated, the post has already been inserted, so we want the one before that

if ($bbuserinfo['allemail']==0) {
$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'
AND user.lastactivity>'$lastposttime[dateline]'");
} else {

$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'");
}

$threadinfo[title]=unhtmlspecialchars($threadinfo['title']);

$temp = $bbuserinfo['username'];
if ($postid) {
$postinfo = getpostinfo($postid);
$bbuserinfo['username'] = unhtmlspecialchars($postinfo['username']);
$bbuserinfo['email'] = unhtmlspecialchars($postinfo['email']);
$postemail = $bbuserinfo['email'];
} else {
if (!$bbuserinfo['userid']) {
$bbuserinfo['username'] = unhtmlspecialchars($postusername);
$bbuserinfo['email'] = unhtmlspecialchars($postuseremail);
$postemail = $bbuserinfo['email'];
} else {
$bbuserinfo['username'] = unhtmlspecialchars($bbuserinfo['username']);
$bbuserinfo['email'] = unhtmlspecialchars($bbuserinfo['email']);
$postemail = $bbuserinfo['email'];
}
}
while ($touser=$DB_site->fetch_array($useremails)) {
$touser['username']=unhtmlspecialchars($touser['username']);

............................................


Since bbuserinfo userid, email, username are available and allemail in in the same user table I would think that it would be called up with no problem too.

Any ideas?

Parker

Chen
22 Mar 2002, 14:33
Oh ok I see the problem now, you are coding this the wrong way.

Replace this:
$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'
AND user.lastactivity>'$lastposttime[dateline]'");

$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'");

And add this:
if (!$touser['allemail'] and $touser['lastactivity']<=$lastposttime['dateline'])
continue;
Right after this:
while ($touser=$DB_site->fetch_array($useremails)) {

Parker Clack
22 Mar 2002, 14:50
Ok so I would end up with

$lastposttime=$DB_site->query_first("SELECT dateline
FROM post
WHERE threadid='$threadid'
ORDER BY dateline DESC
LIMIT ".iif($moderated, '1,1', '1'));
// if it's moderated, the post has already been inserted, so we want the one before that

$useremails=$DB_site->query("SELECT user.*
FROM subscribethread,user
WHERE subscribethread.threadid='$threadid'
AND subscribethread.userid=user.userid
AND user.userid<>'$userid'");


$threadinfo[title]=unhtmlspecialchars($threadinfo['title']);

$temp = $bbuserinfo['username'];
if ($postid) {
$postinfo = getpostinfo($postid);
$bbuserinfo['username'] = unhtmlspecialchars($postinfo['username']);
$bbuserinfo['email'] = unhtmlspecialchars($postinfo['email']);
$postemail = $bbuserinfo['email'];
} else {
if (!$bbuserinfo['userid']) {
$bbuserinfo['username'] = unhtmlspecialchars($postusername);
$bbuserinfo['email'] = unhtmlspecialchars($postuseremail);
$postemail = $bbuserinfo['email'];
} else {
$bbuserinfo['username'] = unhtmlspecialchars($bbuserinfo['username']);
$bbuserinfo['email'] = unhtmlspecialchars($bbuserinfo['email']);
$postemail = $bbuserinfo['email'];
}
}
while ($touser=$DB_site->fetch_array($useremails)) {
if (!$touser['allemail'] and $touser['lastactivity']<=$lastposttime['dateline'])
continue;


Correct?

Thanks,
Parker

Chen
22 Mar 2002, 15:03
Yes.

Parker Clack
22 Mar 2002, 15:13
Chen:

Again that did it and again you have helped me out a great deal.

Thanks,
Parker