Creating array of loop

174
March 03, 2017, at 07:37 AM

I have 2 tables, "header" and "mach":

header:

STATO |ID |CAMPIONATO
Italy |5  |Serie A
Spain |1  |Primera Division
France|2  |Coppe de France

mach:

STATO |home     |away     |scoreH|scoreA|
Italy |juve     |Milan    |0     |0     |
Italy |Lazio    |Roma     |0     |1     |
Spain |Deportivo|Bilbao   |1     |0     |
Spain |A Madrid |Sevilla  |1     |2     |
France|Lille    |Perigord |0     |0     |

I use the following PHP code to extract data. Should I create an array that contains the header and the group matches

$num=0;
$mach=-1;
foreach($first as $row2){  // cycling once
           foreach($header as $row){   //    cycles x times
                    ....        //Here recover the header data
                    $stato;
                    $id;
                    $campionato

                        for($i=0;$i<$count;++$i){   //   in $count know how many times I have to do the cycle for each header (stato)
                        $mach=$mach+1;
                           ....            // Here recover the mach data
                           $home;
                           $away;
                           $scoreH;
                           $scoreA;
                        $info[$mach]= array('home'=>$home,'away'=>$away,'scoreH'=>$scoreH,'scoreA'=>$scoreA);
                        $groups[$num]=array($info[$mach]);
                        }//end for cycles
                        $headerArray[$num]=array('header'=>['stato'=>$stato,'id'=>$id,'campionato'=>$campionato],'mach'=>$groups[$um]);
            $num++;
           } //end header cycles
                       $blockArray[]=array('incontri'=>$headerArray);
} //end first cycle
                       print_r($blockArray);

The problem is in the $groups that returns all date match.(italy,Spain,France) no only groups of header. If you use this line of PHP code:

array_push ($groups,$info[$mach]);

instead of:

$Groups[$num] = array($info[$mach]);

instead returns only the last match (cycle for) for each header.

I would like to create this array

['incontri'=>
[
header=>
    ['stato'=>Italy,'id'=>5,'campionato'=>Serie A],
mach=>
    ['home'=>Juve,'away'=>Milan,'scoreH'=>0,'scoreA'=>0],
    ['home'=>Lazio,'away'=>Roma,'scoreH'=>0,'scoreA'=>0]
],
[....],
]

What am I doing wrong?

READ ALSO
How to check if there exists a key in an array that contains a certain string in php?

How to check if there exists a key in an array that contains a certain string in php?

I am working on a webapp right now in PHPSo far there is a defined array with the following structure:

287
Uploading multiple files to PHP and storing Filepath etc in SQL Database

Uploading multiple files to PHP and storing Filepath etc in SQL Database

I am attempting to upload multiple files to a folder using PHP and then add the file path etc to a SQL database

228
Count characters for last 50 rows

Count characters for last 50 rows

I have this query running on a scriptI'm like to get a total of characters from last 50 rows of file_title column

211
Limit the number of users that can run a php script within a 5 minute time frame

Limit the number of users that can run a php script within a 5 minute time frame

I'm building a simple php script that queries a mysql database to see if a username existsIt would just be ?user=example@gmail

253