我试图通过使用php下拉列表来获取一个又一个的列表。我的代码现在是这样的:
$con = mysql_connect($server,$user_name,$password,$database);
$db_found = mysql_select_db($database, $con);
if ($db_found) {
print "Database Found ";
}
else {
print "Database NOT Found ";
}
$result = mysql_query($con,$db_found,"SELECT
connection_log.user,count(*)
as 'connection_count', sum(TIMESTAMPDIFF(MINUTE,
connection_log.logondate,connection_log.logoffdate))
as `connection_time`
FROM connection_log
INNER JOIN users
ON connection_log.user=users.user WHERE users.groups
LIKE '%cpg_sirket_dyo%'
and connection_log.logondate>='2015-09-01 00:00:00'
and connection_log.logoffdate<'2015-10-01 00:00:00'
group by connection_log.user
order by connection_count desc");
while ($row = mysql_fetch_array($result)) {
echo $row['name']."<br />";
}
但是当我运行这个php时,我会得到一些错误,如下所示:
发现数据库PHP警告:mysql_query()最多需要2个参数,3>在第22行的/var/www/html/test.PHP中给定PHP警告:mysql_fetch_array()要求参数1为resource,null>在第23行的/var/www/html/test.PHP中给定
你知道吗?
mysql_query
mysql_query(字符串$query[,资源$link_identifier=NULL])
只需要两个参数需要
1) 您的查询。
2) MySQL连接
您只需在mysql_query中删除数据库名称,还可以交换查询和连接的位置
$result = mysql_query("SELECT....",$con);
在列和表名中使用反勾号,而不是引用
使用更正您的问题
SELECT
connection_log.user,count(*)
as `connection_count`, sum(TIMESTAMPDIFF(MINUTE,
connection_log.logondate,connection_log.logoffdate))
as `connection_time`
FROM connection_log
INNER JOIN users
ON connection_log.user=users.user WHERE users.groups
LIKE '%cpg_sirket_dyo%'
and connection_log.logondate>='2015-09-01 00:00:00'
and connection_log.logoffdate<'2015-10-01 00:00:00'
group by connection_log.user
order by connection_count desc
注意:-mysql不推荐使用mysqli或PDO
看看http://php.net/manual/en/function.mysql-query.php
只有两个参数,查询和(可选的)连接,所以你必须使用:
$result = mysql_query("SELECT ...", $con);
您需要从函数中删除此$db_found:
http://php.net/manual/en/function.mysql-query.php
$result = mysql_query($yourQuery,$con);
也可以尝试使用mysqli,而不是不推荐使用的mysql。
使用PHP 时MySQL与MySQLi的比较
使用以下代码,
$con = mysql_connect($server,$user_name,$password);
$db_found = mysql_select_db($database);
if ($db_found) {
print "Database Found ";
}
else {
print "Database NOT Found ";
}
$result = mysql_query("YOUR QUERY",$con);
while ($row = mysql_fetch_array($result)) {
echo $row['name']."<br />";
}