Multiple query data into single HTML Table (PHP, MySQL)

前端 未结 3 1914
夕颜
夕颜 2021-01-23 11:18

Here is my current code. I\'m trying to display data from three separate queries into a single table with multiple columns. Is my while statement wrong here? It\'s printing 1 ta

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 11:57

    $data = array();
    
    while($row = mysql_fetch_assoc($july)) {$data['row'][] = $row;}
    while($row = mysql_fetch_assoc($aug))  {$data['row2'][] = $row;}
    while($row = mysql_fetch_assoc($sept)) {$data['row3'][] = $row;}
    
    $count = count($data['row']);
    
    for($i=0;$i<=$count;$i++)
    {
        echo '';
            if(($i % 3) == 1)
            {
                echo "" . $data['row3'][$i]['cUsername'] . "";
                echo "" . $data['row3'][$i]['postCount'] . "";
            }else if(($i % 2) == 1)
            {
                echo "" . $data['row2'][$i]['cUsername'] . "";
                echo "" . $data['row2'][$i]['postCount'] . "";
            }else /*Never try find remainder of 1 as theres always a multiple of 1*/
            {
                echo "" . $data['row'][$i]['cUsername'] . "";
                echo "" . $data['row'][$i]['postCount'] . "";
            }
        echo '';
    }
    

    By fetching the results individually into a local array instead of trying to fetch 3 different rows at the same time you should do them individually and store them in a local variable, just unset the variable after words if its a large array.

    my code is offered as untested.

提交回复
热议问题