-2

你能告诉我如何把这个查询放在表中..

<?
$username="root";
$password="kermit";
$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);
mysql_close();

谢谢 :)

4

2 回答 2

1

除了您在'result = ...'前面缺少'$'这一事实之外。不清楚你在问什么。您想获取 SELECT 查询的结果并将该数据插入到其他表中吗?假设 'other_table' 具有适当的架构,那么它可能就像像这样添加前缀一样简单: $query = "INSERT INTO other_table (SELECT user.firstname,....)"'

于 2013-07-24T00:25:56.363 回答
0

阅读 mysql_fetch_array 函数,您的表填充应该包含在这样的块中,例如:

while($row=mysql_fetch_array($result)){
    echo "<tr><td>".$row["firstname"]."</td></tr>";
}

但是,由于您是 MySQL 新手,我对您的最佳建议是,在您养成使用上述习惯之前,首先学习如何通过 PDO 命名空间使用 MySQL。

http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

于 2013-07-24T01:15:10.060 回答