0

我正在尝试除以表中的行数,此时我正在输入要手动除以的值:

<?php
$result10 = $result10 * 100 / 10 (<-- Result from count)
?>

我想我需要计算行数并用 $query_result 替换 10 但我已经尝试过这个并且不确定该怎么做以及是否可能?

提前致谢

4

3 回答 3

1

作为如何在查询中执行此操作的示例:

select result10 / (select count(*) from <yourquery>)
from <your query>

如果您正在做一个简单的平均,那么这可能是最合适的解决方案:

select avg(colx)
from t
于 2013-04-21T00:45:41.827 回答
0

另一种你可以做到的方式

 <?php
define('HOST','hostdetails');
define('USER','userdetails');
define('PASS','passdetails');
define('DB','dbdetails');

$mysqli = new mysqli(HOST,USER,PASS,DB);
$sql = "SELECT COUNT(*) FROM table";
$stmt = $mysqli->prepare($sql);
$stmt->execute();
$rowcount = $stmt->num_rows;
//$result10 -> add your variable for result10 here, however you are generating it...

$result10 = (($result10*100)/$rowcount);
?>
于 2013-04-21T00:57:01.093 回答
0
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database", $link);

$result = mysql_query("SELECT * FROM my_table", $link);
$num_rows = mysql_num_rows($result);
$result10 = $result10 * 100 / $num_rows (<-- Result from count)
于 2013-04-21T05:18:03.867 回答