php multidimensional array for html table

2019-09-04 16:49发布

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

1条回答
再贱就再见
2楼-- · 2019-09-04 17:01

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
}
查看更多
登录 后发表回答