简体   繁体   English

PHP / MySQL数组/数字交叉表

[英]PHP/MySQL arrays/numrows crosstabulation

Im trying to get crosstabulation count with next code (this is relevant piece) wich doesn't work 我试图用下一个代码(这是相关的部分)获得交叉表计数,但不起作用

<?php
foreach($row as &$val_row)
{
    foreach($col as &$val_col)
    {
        $count=mysql_num_rows(mysql_query("SELECT whatever FROM data WHERE 
$field_row='$val_row' AND $field_col='$val_col'"));

        echo $count;
    }
}
?>

Im just getting a hang of using arrays, Im wondering why this doesn't work. 我只是迷恋使用数组,我想知道为什么这行不通。 I get only $count once right, other results are 0... 我一次只得到$ count,其他结果为0 ...

In this case, i have crosstabulation of 2 types of answers. 在这种情况下,我可以交叉列出2种类型的答案。 Gender (Male, Female), Question (yes,no) My idea was to run trough both arrays with foreach and to build a table, for every field to do a query of current value of array for row and column.. It simply doesn't work.. I think that I'm doing something wrong with recursion or variable lifespan.. I'm realy confused.. 性别(男,女),问题(是,否)我的想法是使用foreach运行两个数组,并构建一个表,以便每个字段都可以查询行和列的数组的当前值。没用。我认为递归或可变寿命存在一些问题。我真的很困惑。

The problem was in mysql table data. 问题出在mysql表数据中。 I had imported data from some lousy .csv As soon as I got correct data in table, everything started working the way it should be... Please delete this question as it doesn't have any logical purpose... 我已经从一些糟糕的.csv中导入了数据。一旦我在表中获得了正确的数据,一切便开始以应有的方式运行...请删除此问题,因为它没有任何逻辑目的...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM