0

Hello All,
I have fetched array from database,
it is two dimentinal array.
and want to print it into html table.
But when print it's need attribute while printing it.
here is code:

<tr>
    <th>Sr.No.</th>
    <th>Skill type</th>
    <th>Skill Name</th>
    <th>Project</th>
    <th>Practice</th>
    <th>Description </th>
</tr>
<?
$skills_1=[HERE I HAVE FETCHED ARRAY FROM DATABASE];
?>
<table class='GoalsettingTable'>
    Skills used by employee:
<tr>
    <th>Sr.No.</th>
    <th>Skill type</th>
    <th>Skill Name</th>
    <th>Project</th>
    <th>Practice</th>
    <th>Description </th>
</tr>
<?
if(sizeof($skills_1)>0)
{
    $array_size=sizeof($skills_1);
    for ($index=0;$index < $array_size ;$index++)
    {
        echo "<tr>";     
        for ($inner_index=0;$inner_index < 6 ;$inner_index++)
        {
            echo $index;
            echo $skills_1[$index]['skill_id'];
            echo $skills_1[$index]['skill_id'];
            echo $skills_1[$index]['practice'];
            echo $skills_1[$index]['project'];
        }
        echo "</tr>"; */
    }

}
?>
</table>

But its print incorrect.
it is printing each array in each <td>

I want to print inner loop like echo "<td>".$skills_1[$index][$inner_index]."</td>";
but it is not printing because of attribute.

how can i print this?

Edited by Priti_P

3
Contributors
2
Replies
28
Views
3 Years
Discussion Span
Last Post by jsuna
0

It would be helpful if we see the actual data in the array. Put this code between lines 10 and 11:

die(print_r($skills_1, 1));

Post the output here.

It is also (usually) easier to use a foreach loop to process an array instead of all the for stuff.

Edited by broj1

1

Try...

if(count($skills_1))
{
    foreach($skills_1 as $i=>$skills)
    {
        echo '<tr>';
        foreach($skills as $key=>$skilldata)
            echo '<td>'.$skilldata.'</td>';
        echo '</tr>';
    }
}

Hope it helps!

Votes + Comments
nice bro.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.