Jump to content

Displaying data from database into a 2 dimensional table


anonymouse

Recommended Posts

Good day!

 

I'm a beginner in PHP and I'm not expecting a full coding for this qestion. I'm just looking for hints and pointers as to how to solve this problem so that I can learn it myself.

 

I have a question here about displaying data from database into a 2 dimensional table. Say I have a 2 dimensional table something like below

 

57741282.png

 

And I have a data in the database that corresponds to something like R1C3 and R2C1, how do I display the data on the table so that it looks something like below

 

41006833.png

 

Any help would be greatly appreciate.

 

Thanks and have a nice day :)

I would recommend that you use a 2D array in PHP to store the value of the cells before printing out the entire table..

 

In your example, the code would be something along the lines of

 

...
$table[1][3] = "Data";
$table[2][1] = "Data";
...

 

Then, to output the code into a table:

 

foreach($table as $row){
echo "<tr>";
foreach($row as $cell){
echo "<td>".$cell."</td>";
}
echo "</tr>";
}

 

HTH

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.