[英]mysql_num_rows and condition
Hi guys I am trying to use something more efficient instead of using mysql_num_rows
from multiple queries. 嗨伙计们,我正在尝试使用更高效的东西,而不是使用来自多个查询的
mysql_num_rows
。 Am I able to use one query and for example count mysql_num_rows()
based on condition if $type=="a"
? 我是否可以使用一个查询,例如,如果
$type=="a"
则根据条件计算mysql_num_rows()
? And declare variable for each.. for b rows, c rows, d rows etc. Thank you 并为每个..声明变量为b行,c行,d行等等。谢谢
$rows_a = mysql_query("SELECT $type FROM table WHERE $type = 'a'");
$a_rows = mysql_num_rows($rows_a);
$rows_b = mysql_query("SELECT $type FROM table WHERE $type = 'b'");
$b_rows = mysql_num_rows($rows_b);
$rows_c = mysql_query("SELECT $type FROM table WHERE $type = 'c'");
$c_rows = mysql_num_rows($rows_c);
$rows_d = mysql_query("SELECT $type FROM table WHERE $type = 'd'");
$d_rows = mysql_num_rows($rows_d);
SELECT COUNT(id), type FROM table GROUP BY type
Could be like this : ( if no primary ID column) 可能是这样的:(如果没有主ID列)
SELECT COUNT(*) as num_rows, type FROM table WHERE type IN ('a', 'b', 'c', 'd') GROUP BY type
or dynamic : 或动态:
SELECT COUNT(*) as num_rows, type FROM table WHERE type IN ('select types from a sub query') GROUP BY type
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.