简体   繁体   中英

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...

In this case, i have crosstabulation of 2 types of answers. 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..

The problem was in mysql table data. 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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