PHP cron作业代码运行不正常

时间:2013-07-19 01:01:02

标签: php cron moodle

我的cron作业没有从我的moodle数据库生成报告。

我的查询没有错误,它只是不显示结果。

顺便说一句,我的moodle版本是2.2

任何帮助?

这是php代码:

<?
    $username="****";
    $password="#####";
    $database="moodle";


    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query = "SELECT user.firstname, user.lastname, stats.userid, stats.roleid, SUM(             statsreads ) AS numreads, SUM( statswrites ) AS numwrites, SUM( statsreads ) + SUM( statswrites ) AS totalactivity FROM  `mdl_stats_user_daily` stats, `mdl_user` user WHERE userid IN (SELECT userid FROM mdl_role_assignments WHERE roleid IN (1,2,3,4)) AND user.id = stats.userid AND stats.timeend > ".(time() - 604800)." GROUP BY userid ORDER BY totalactivity DESC";


    $result=mysql_query($query);
    $num_rows = mysql_num_rows($result);

    echo "$num_rows Rows\n";
    echo "To: arjay.almanzor@gmail.com\n";
    echo "From: \"Arjay Almanzor\" root@sesc.org\n";
    echo "Subject: Weekly Moodle Report\n";
    echo "Content-Type: text/html; charset=\"us-ascii\"\n";



    echo "<html> <body>\n";
    echo "<h1>Moodle Report</h1>";
    echo "as of ".date('l jS \of F Y h:i:s A');
    echo "<h2>Top Users This Week</h1>\n";
    echo "<table>\n";
    echo "<tr><td>First Name</td><td>Last Name</td><td>Total Activity(Pageviews/Updates) </td>";
    while ($row = mysql_fetch_assoc($result)) {
        echo "<tr>"; 
        echo "<td>".$row['firstname']."</td>"; 
        echo "<td>".$row['lastname']."</td>";
        echo "<td>".$row['totalactivity']."</td>";

        echo "</tr>";
        echo "\n";
    }
    echo "</table>\n";

    $query = "SELECT user.firstname, user.lastname, stats.userid, stats.roleid, SUM( statsreads ) AS numreads, SUM( statswrites ) AS numwrites, SUM( statsreads ) + SUM( statswrites ) AS totalactivity FROM  `mdl_stats_user_monthly` stats, `mdl_user` user WHERE userid IN (SELECT userid FROM mdl_role_assignments WHERE roleid IN (1,2,3,4)) AND user.id = stats.userid AND stats.timeend > ".(time() - 2419200)." GROUP BY userid ORDER BY totalactivity DESC";


    $result=mysql_query($query);
    echo "<h2>Top Users This Month</h1>\n";
    echo "<table>\n";
    echo "<tr><td>First Name</td><td>Last Name</td><td>Total Activity(Pageviews/Updates)  </td>";
    while ($row = mysql_fetch_assoc($result)) {
        echo "<tr>"; 
        echo "<td>".$row['firstname']."</td>"; 
        echo "<td>".$row['lastname']."</td>";
        echo "<td>".$row['totalactivity']."</td>";

        echo "</tr>";
        echo "\n";
    }
    echo "</table>\n";
    echo "</body> </html>";
    mysql_close();
?>

0 个答案:

没有答案