2014-09-02 47 views
1

我需要將文章的文本轉移到視圖。分佈在三列的文字,像這樣:如何在標記中的幾列之間劃分數據庫中的文本

<div class="row"> 
    <div class="col-md-4"> 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
    </div> 
    <div class="col-md-4"> 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
    </div> 
    <div class="col-md-4"> 
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. 
    </div> 
</div> 

但是,我怎麼能分兩列之間的文本標記,從數據庫,當談到?

+0

您可以在數據庫中包含3列來保存每段文本,也可以將所有數據存儲在一個文本字段中,並在從db中將數據拉回時在每個不同斷點處獲取子字符串 – Alex 2014-09-02 12:36:29

回答

2

解決方案1:

第一溶液使用3條數據庫列來保存數據

---------------------------------- 
       POSTS 
---------------------------------- 
post_id       PK 
column_1      TEXT 
column_2      TEXT 
column_3      TEXT 

查詢:SELECT * FROM posts WHERE post_id=your_id將返回的陣列保持柱的ID以及您的每一個列,如果你在HTML中獲取關聯數組,你可以做

<div class="wrapper"> 
    <div class="col4"><?php echo $text['column_1'] ?></div> 
    <div class="col4"><?php echo $text['column_2'] ?></div> 
    <div class="col4"><?php echo $text['column_3'] ?></div> 
</div> 

解決方案2:

第二解決方案使用1條數據庫列來容納所有文本,然後分割的是給定長度

---------------------------------- 
       POSTS 
---------------------------------- 
post_id       PK 
post_data      LONGTEXT 

查詢:SELECT post_data FROM posts WHERE post_id=your_id將返回的陣列保持後數據,則可以做

<div class="wrapper"> 
    <div class="col4"><?php echo subtr($text['post_data'], 0, 250) ?></div> 
    <div class="col4"><?php echo subtr($text['post_data'], 251, 500) ?></div> 
    <div class="col4"><?php echo subtr($text['post_data'], 501, 750) ?></div> 
</div> 

希望這會有所幫助。

相關問題