简体   繁体   中英

php multidimensional array for html table

ok consider I have the following data from my database:

string '20' 
string '14' 
float 6

string '15'
string '14' 
float 10

20 & 15 are project ids 14 is the user id and the floats are hours

I need to compile this data to be printed to a HTML table. The answer seems to be a multidimensional array.

so I assume this will look like this:

array (size 3)

0=> [project codes]
1=> [data (floats)] 
2=> [user id's] 

Is it possible to recursively search my returned mysql results for the project code and the user id and pop the float into the correct position in this case:

for project 20 and user id 14 insert 6 hours [20][6][14].

load the array from the database "fetch loop"

$arr = array("project"=>$row['project_id'], "data"=>$row['data'], "userid"=>$row['user_id']);

display the data loop

foreach ($arr as $valarr){
   echo $valarr['data']; // your tds' line with the data
}

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