[英]Accessing mysql_query results
I have the following columns in a table of mine ; 我的桌子上有以下几栏;
id / owner / del / eq / type id /所有者/ del / eq /类型
IF there are 2x of the same ID and 2x of the same type in one row. 如果一行中有2x个相同ID和2x相同类型。 You cannot add a 3rd.
您无法添加第三名。 I can do this with a PHP If statement.
我可以使用PHP If语句执行此操作。 But I have tried to count using this ;
但是我试图用这个数;
$tot = mysql_query("SELECT COUNT(*) FROM item WHERE id='$id'AND type='1'");
$tot1 = mysql_fetch_array($tot);
Here it should count the rows where the ID ( that matches the person logged in ) and how many of them are also type 1. But when I echo this I just get the word "Array" 在这里它应该计算ID(与登录的人匹配)所在的行以及其中的行数也为1。但是当我回显此行时,我只会得到“ Array”一词。
The result of mysql_fetch_array
is an array that maps columns to their values in the current row, both assosciatively and by index. mysql_fetch_array
的结果是一个数组,该数组将列关联并按索引映射到当前行中它们的值。 So, in this case, you can get the result of count(*)
by referring to $tot1[0]
. 因此,在这种情况下,您可以通过引用
$tot1[0]
获得count(*)
的结果。
而不是回显,请使用var_dump()或print_r()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.