MyBB Community Forums

Full Version: Adding a new query for the memberlist
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am working on integrating a Flight Simulator ACAR package which, basically, records how long a pilot has flown. The problem I am having is how to get the total hours a filot has flown to display in the memberlist.

I am trying to add the query in the memberlist.php page, but I'm not sure if that is the proper place.

The original query is
PHP Code:
$query_hours "SELECT sec_to_time(sum(time_to_sec(t2.duration))) AS duration_sum FROM
"
.TABLE_PREFIX."users t1, reports t2 WHERE t1.uid=$id AND t1.uid=t2.pilot_id";

            
$result_hours mysql_query($query_hours);
        
            if (
mysql_numrows($result_hours) > 0) {
            
$time mysql_result($result_hours,0,"duration_sum"); 

Any help is appreciated as I'm stuck.
Okay, I have it somewhat working. Instead of actually displaying the total, it's now just displaying "Resource id #28". I don't know how to get it to display the actual total flight number though.

Here's what I have now for the query:
PHP Code:
$users['flight_time'] = $db->query("
    SELECT sec_to_time(sum(time_to_sec(t2.duration)))
    FROM "
.TABLE_PREFIX."users t1, reports t2
    WHERE t1.uid='uid' AND t1.uid=t2.pilot_id
    LIMIT $start, "
.$mybb->settings['membersperpage']
    ); 

Any help?
Try this:
PHP Code:
$users['flight_time'] = $db->fetch_field($db->query("
    SELECT sec_to_time(sum(time_to_sec(t2.duration)))
    FROM "
.TABLE_PREFIX."users t1, reports t2
    WHERE t1.uid='uid' AND t1.uid=t2.pilot_id
    LIMIT $start, "
.$mybb->settings['membersperpage']
    ), 
0); 
Thanks Dennis, but it's not working.

Where exactly should I put the query?
After this line?
PHP Code:
$plugins->run_hooks("memberlist_user"); 
It's still not working.

I am completely confused by this.
When looking at the first one is t1.uid=$id and in the query you try to use t1.uid='uid' ?
Also try this instead:

In memberlist.php, find:
PHP Code:
$plugins->run_hooks("memberlist_user"); 
After that line, add:
PHP Code:
$users['flight_time'] = $db->fetch_field($db->query("
    SELECT sec_to_time(sum(time_to_sec(t2.duration)))
    FROM "
.TABLE_PREFIX."users t1, reports t2
    WHERE t1.uid='{$users['uid']}' AND t1.uid=t2.pilot_id"
), 0); 
Reference URL's