I'm trying to further customize an existing modification for my site/forum, but unfortunately the author who I've asked for support has little spare time at the moment.
Can someone advise where I might be going wrong with this query?
SELECT date FROM {db_prefix}log_activity
WHERE date = 2015-12-25
( SELECT COUNT(*) AS total FROM {db_prefix}log_online
WHERE ID_MEMBER = $memberID );
I am basically looking to check if my specified date appears in {db_prefix}log_activity and if it does, trigger my action for all members found in {db_prefix}log_online
(more to the code but I think the above part is what causing me issues..)
Full code of my attempts:
if (!in_array('test',$currentBadges))
{
$resultgroup = $smcFunc['db_query']('', "
SELECT date FROM {db_prefix}log_activity
WHERE date = 2015-04-20
( SELECT COUNT(*) AS total FROM {db_prefix}log_online
WHERE ID_MEMBER = $memberID );
");
$totalRow = $smcFunc['db_fetch_assoc']($resultgroup);
{
$badgeAction = 'test';
if (!in_array($badgeAction,$currentBadges) && $totalRow['total'] >= 1)
{
$badgeID = GetBadgeIDByAction($badgeAction);
$ret = AddBadgeToMember($memberID,$badgeID,false);
if ($ret == true)
{
$currentBadges[] = $badgeAction;
$newBadges[] = $badgeAction;
}
}
}
//end badge code
}
I've never used this site before so hopefully that format's somewhat readable.. :P
Basically what I am attempting to do is: IF (date) = today AND (member) has logged in THEN award badge...
Log of changed attempts:
"WHERE date = 2015-04-20"
WHERE date = "2015-04-20"
As per your edit in using "WHERE date = 2015-04-20"
You are using double quotes inside a double-quoted query.
Use single quotes like this and as per what you have in your originally posted code:
$resultgroup = $smcFunc['db_query']('', "
SELECT date FROM {db_prefix}log_activity
WHERE date = '2015-04-20'
( SELECT COUNT(*) AS total FROM {db_prefix}log_online
WHERE ID_MEMBER = $memberID );
");
Plus, if $memberID
is not an integer, it would also need to be quoted.
I.e.:
$resultgroup = $smcFunc['db_query']('', "
SELECT date FROM {db_prefix}log_activity
WHERE date = '2015-04-20'
( SELECT COUNT(*) AS total FROM {db_prefix}log_online
WHERE ID_MEMBER = '$memberID' );
");
For more information on this, read the following on Stack
and string functions on the MySQL.com website: