如何在标记中的几列之间划分数据库中的文本

时间:2014-09-02 12:33:39

标签: html css laravel twitter-bootstrap-3

我需要将文章的文字转移到视图。文本分布在三列,如下所示:

<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>

但是,当它来自数据库时,如何在标记中的列之间划分文本?

1 个答案:

答案 0 :(得分: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>

希望这有帮助。