您能告诉我如何将此查询放入表格中吗?
<?
$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();
谢谢:)
答案 0 :(得分:1)
除了你在'result = ...'前面错过'$'这一事实。目前尚不清楚你在问什么。是否要获取SELECT查询的结果并将该数据插入到其他表中?假设'other_table'具有适当的模式,那么它可能就像前缀这样简单:$ query =“INSERT INTO other_table(SELECT user.firstname,....)”'
答案 1 :(得分:0)
阅读mysql_fetch_array函数,您的表填充应该包含在这样的块中,例如:
while($row=mysql_fetch_array($result)){
echo "<tr><td>".$row["firstname"]."</td></tr>";
}
但是,既然你是MySQL的新手,我最好的建议就是在你习惯使用上述习惯之前先学习如何通过PDO命名空间使用MySQL。