PHP HTML Template with Loop capabilities

前端 未结 3 527
故里飘歌
故里飘歌 2021-01-07 07:28

I would like to ask some help and ideas on how to implement a loop inside the template. I can do foearch below but how can i include it to the template and show it in the re

3条回答
  •  旧巷少年郎
    2021-01-07 07:52

    PHP itself is as good at templates as any other engine.
    No need anything else

    $pagetitle = "My Template Class";
    foreach($results as $row) {
      $row['date'] = date("m/d/y");
      $data[] = $row;
    }
    $data = chunk_split($data,3);    
    

    Then in template

    
    
    <?=$pagetitle?>
    
    
     

    Hello !

    The time is:

    Embedded PHP works in the template

    But embed PHP in the data is a VERY BAD IDEA

    I made your example a bit more complicated yet closer to the real life.
    It will print your table in the rows by 3 columns in each

提交回复
热议问题