php - Two arrays into one table. First array vertical, second horizontal -


name bob   jim   moe   rob id   555   666   777   888 lvl  1     2     3     4 

this (part of) array:

array (     [heroes] => array         (             [0] => array                 (                     [paragonlevel] => 384                     [name] => barbecue                     [id] => 35335691                     [level] => 70                     [hardcore] =>                      [gender] => 0                     [dead] =>                      [class] => barbarian                     [last-updated] => 1400233350                 )              [1] => array                 (                     [paragonlevel] => 384                     [name] => ethereal                     [id] => 43477852                     [level] => 70                     [hardcore] =>                      [gender] => 1                     [dead] =>                      [class] => crusader                     [last-updated] => 1400283921                 ) 

[this goes upto 8. want paragonlevel,name.id etc on first vertical line. want next column being filled character data, , next column next char , on]

name, id , lvl in 1 array in table. see vertical part. "name" see names on horizontal line.. thats second array.

currently can populate vertical line.. cant seem populate horizontal right.

$herokeys   = array_keys($career_data["heroes"][0]); echo "<table width='700' border='5' summary='table testing.'><caption id='bhcc'>basic hero chart ($para)</caption>"; foreach(array_slice($herokeys, 1) $herokey) {    $herokey = ucwords($herokey);    echo "<tr>";    echo "<th id='rowtitle' scope='row'>$herokey</th>";    foreach($career_data["heroes"] $i => $hero) {       $name   = $career_data["heroes"][$i]['name'];       echo "<th id='chname' scope='col'>$name</th>";    }    echo "</tr>"; echo "</table>"; 

how do this?

you can use foreach make vertical format. consider example:

<?php $values_from_db = array(     'heroes' => array(         array(             'paragonlevel' => 384,             'name' => 'barbeque',             'id' => 35335691,             'level' => 70,             'hardcore' => '',             'gender' => 0,             'dead' => '',             'class' => 'barbarian',             'last-updated' => 1400233350,         ),         array(             'paragonlevel' => 384,             'name' => 'ethereal',             'id' => 43477852,             'level' => 70,             'hardcore' => '',             'gender' => 1,             'dead' => '',             'class' => 'crusader',             'last-updated' => 1400283921,         ),         array(             'paragonlevel' => 999,             'name' => 'gm',             'id' => 999999999,             'level' => 999,             'hardcore' => 'yes',             'gender' => 3,             'dead' => '',             'class' => 'god',             'last-updated' => 1400233350,         ),     ), );  // $keys = array_keys($values_from_db['heroes'][0]); $keys = array('name', 'id', 'level'); // needed keys ?>  <table border="1" cellpadding="10"> <?php foreach($keys $value): ?> <tr>     <td style="background-color: yellow;"><?php echo $value; ?></td>     <?php foreach($values_from_db $index => $element): ?>         <?php foreach($element $k => $v): ?>             <td><?php echo $v[$value]; ?></td>         <?php endforeach; ?>     <?php endforeach; ?> </tr> <?php endforeach; ?> </table> 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -