Dynamic create rows and colum with the help of PHP and HTML

前端 未结 5 1702
面向向阳花
面向向阳花 2021-01-01 02:17

I want to create dynamic rows and column with the help of PHP and HTML but I am little confused about this code so some help is definitely appreciated.

&l         


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 02:27

    Something like this, maybe

    function create_table()

    function create_table($data) {
      $res = '';
      $max_data = sizeof($data);
      $ctr = 1;
      foreach ($data as $db_data) {
        if ($ctr % 2 == 0) $res .= '';
        else {
          if ($ctr < $max_data) $res .= '';
          else $res .= '';
          }
        $ctr++;
        }
      return $res . '
    ' . $db_data['id']. '
    ' . $db_data['id']. '
    ' . $db_data['id']. '
    '; }

    Course, you can modify style of table to fit your needs.

    Call it like this:

    echo create_table($data);
    

    Output

    (example for 7, 4, 3 and 8 id's) enter image description here

    It returns table with same number of rowsin each column if you pass even number of id's or table where last row is merged if you pass odd number of id's into function.

提交回复
热议问题