iT邦幫忙

1

PHP-資料庫串接handlebars顯示到HTML筆記(1)

  • 分享至 

  • xImage
  •  

data.php

$sql = 'SELECT * FROM commodity ORDER BY id ASC';
$statement = $pdo->prepare($sql);
$statement->execute();
$commodity = $statement->fetchAll(PDO::FETCH_ASSOC);
?>
<script>
	var commodity = <?php echo json_encode($commodity, JSON_NUMERIC_CHECK)?>;
</script>

index.php

<?php include('data.php');?>
<div id="commodity-list">
     <div class="close">x</div>
        <!-- 此為商品清單Template -->
</div>

<script id="commodity-list-item-template" type="text/x-handlebars-template">
  <div class="container">
    <img src="{{img}}" alt="{{img}}">
    <div class="content">
      <div class="book-name">{{book_name}}</div>
      <div class="author">作者:<span>{{author}}}/span></div>
      <div class="Publishing-house">出版社:<span>{{Publishing_house}}</span></div>
      <div class="Publication-date">出版日期:<span>{{Publication_date}}</span></div>
      <div class="price">NT${{price}}</div>
      <div class="button">加入購物車</div>
    </div>
  </div>
</script>

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言