Hey, guys, I need a little help.

This is a report in Wordpress that I need to modify. I need to take the data exemplified by the following table and insert it into a column in the report. (Just the last column.)

I’ve got a query that returns the following data (abbreviated):

SELECT week( time ) wknum,  sll.uid UID, sll.user_login, count( sll.uid ) num_logins
FROM gga_simple_login_log sll
WHERE login_result = 1
GROUP BY wknum, sll.uid
ORDER BY wknum, sll.uid
LIMIT 20


wknumUIDuser_loginnum_logins
312017David1
324ggray2
329customer2
3231northwestteam2
321147358265
3211793935112
321620924931
3217380A19251
3219280A70542
321930Yael2
321961A0368911
3219970A79671
322017David2
334ggray3
339customer2
3322floridateam1
3327southernteam1
3398958482
331045193331
331065234252



The point of the above data is to show some conditions where the last column has non-zero / non-null values.

Here is an example where I’m grabbing exactly ONE week# and UID, which is closer to the actual use-case:

SELECT week( sll.time ) wknum, sll.uid UID, count( * ) NumLogins FROM gga_simple_login_log sll WHERE sll.login_result = 1 AND UID = 2017 AND week( sll.time ) = 32 LIMIT 0, 30 ;

wknumUIDNumLogins
3220172


That said, here’s the code I’m using in the plugin that’s supposed to grab the 3rd column from the above result (= 2):

$weeklyLoginsQuery = "SELECT count(sll.uid) as NumLogins FROM $wpdb->simple_login_log sll WHERE (sll.login_result=1) AND (week( sll.time ) = week(now())) AND (sll.uid = $theuser->ID )";
$weeklyLogins = $wpdb->get_row($weeklyLoginsQuery );
$user_data[] = '{ '. (empty($weeklyLogins) ? 'oops!' : $weeklyLogins[2]) .' }’;

This is running inside of a loop for the current week (which is 37 or 38 now) and it iterates over the UIDs and grags the NumLogins for that UID.

The problem is … no matter what I do, all I get is either NULL or empty in the result set. I don’t get any numeric data at all, for ANY of the UIDs.

Any idea what’s wrong?  (I’ve tried a whole bunch of different things that all result in the same “nothing” output.

BTW, this is using the data in a table associated with a free WP Plugin named “Simple Login Log”.

I simply need a count of logins by UID for the current (or previous) week.


-David Schwartz



_______________________________________________
azPHP mailing list
azPHP@list.azphp.org
http://list.azphp.org/mailman/listinfo/azphp_list.azphp.org