dongshou1856 2017-01-13 09:11
浏览 55

使用php在bootstrap中动态形成列

i want to dynamically display content in 3 bootstrap colums.

<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<content> 
</div> <---- Problem (should be placed at the very end of the column, 
but the same code should also fill 2nd and 3rd columns)

while i fetch the query to mysql. Also i want object to sort in descending order from left to right (id = 51, id = 50, id = 42 (last digit in the object title is id)) I was able to do that, using row_number and row_number%3=0 row_number%3=1 and row_number%3=2 to display 3 columns, but i have to make 3 queries to the database along with 3 blocks of html(which is bad).

SELECT *
FROM (
    SELECT 
    @row_number:=@row_number + 1 AS rownum, id,title, description, ...etc
    FROM (
        SELECT @row_number:=0) r, flats ORDER BY id DESC) ranked WHERE rownum%3=1 ORDER BY id DESC

But, when i started to implement filters, it caused problems with displaying objects, because not every column had the object i wanted to display, but i had own query for every column. Problems with filters

What i want: Dynamically form 3 separate columns with content to use one MYSQL query. Waiting for your help! Example of 1 of 3 columns:

<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4">
<?php
  $zapros = $DB_con->prepare('SELECT *
FROM (
    SELECT 
    @row_number:=@row_number + 1 AS rownum, id,title, description,type, area,address, square, name, phone, email, price, avito, farpost
    FROM (
        SELECT @row_number:=0) r, flats ORDER BY id DESC) ranked WHERE rownum%3=1 ORDER BY id DESC');
  $zapros->execute();
  $rowsone=$zapros->rowCount();
if($zapros->rowCount() > 0)
  {$tmpCount = 1;

    $count=$zapros->rowCount();
    while($data=$zapros->fetch(PDO::FETCH_ASSOC))
    {
      extract($data);


       $number=$data['id'];
                                              $imagestm=$DB_con->prepare('SELECT file FROM flats_images WHERE post_id=:uid LIMIT 1');
                                              $imagestm->bindParam(':uid',$number);
                                              $imagestm->execute();
                                              $imgrow=$imagestm->fetch(PDO::FETCH_ASSOC);
                                              extract($imgrow);?>

<div class="well-lg well-smallborders">
<a href="flat.php?flat_id=<?php echo $data['id']; ?>">
<img src="/mysql/uploads/<?php echo $imgrow['file']; ?>" class="img-responsive title-image center-block" /></a> 
<div class="flat-price center-block"><?php echo $data['price']; ?><span class="glyphicon glyphicon-rub" aria-hidden="true"></span> </div>
<div class="flat-title"><?php echo $data['title'];?> <?php echo $data['id']; ?></div>
<div class="dimmed-text left"><?php echo $data['type']; ?> </div>
<div class="dimmed-text right"><div class="tooltip_my"><span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span><?php echo $data['area'];?> <span class="tooltiptext"><?php echo $data['address']; ?></span></div></div>
<br>
<div class="dimmed-text left"><div class="tooltip_my"> <span class="glyphicon glyphicon-phone" aria-hidden="true"></span><?php echo $data['phone'];?><span class="tooltiptext"><?php echo $data['name'];?></span></div></div>
<div class="dimmed-text right"> <?php echo $data['square'];?></div>
<table class="flats-table">
 <tr>
 <td colspan="3">
    <button id="collapsar" class="btn btn-info pull-left" data-toggle="collapse" data-target="#hide-me<?php echo $tmpCount;?>"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span class="btntext">Показать миниатюры</span></button>
    <a href="flat.php?flat_id=<?php echo $data['id']; ?>" class="btn btn-info pull-left" ><span class="glyphicon glyphicon-eye-open"></span> <span class="btntext">Подробнее ...</span></a>
    </td>
    </tr>
    <tr>
     <td colspan="3">
 <div id="hide-me<?php echo $tmpCount;?>" class="collapse"> 
<? 
$imagestm2=$DB_con->prepare('SELECT file FROM flats_images WHERE post_id=:uid');
                                              $imagestm2->bindParam(':uid',$number);
                                              $imagestm2->execute();


for ($i = 1; $i <= $imagestm2->rowCount(); $i++) {
  $imgrow2=$imagestm2->fetch(PDO::FETCH_ASSOC);
                                              extract($imgrow2); ?>

<div class="col-xs-6 col-sm-6 col-md-4 col-lg-4">
<div class="thumbnail"> <img src="mysql\uploads\<?php echo $imgrow2['file']; ?>" data-toggle="modal" data-target="#myModal"  class="img-responsive"/></div>
</div>
    <?

} ?>
</div>
     </td>
     </tr>
</table>
</div><?
$tmpCount++;
      }}    
     ?>
     </div>

Actual result i want: Actual result

  • 写回答

2条回答 默认 最新

  • douhezhang8932 2017-01-13 11:14
    关注

    I think you are simply trying to iterate over your results, generate 3 columns of output, and then also apply filters, maybe through Javascript, which hide some of your elements. The simplest way I know to do that is as follows:

    <div class="row">
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
        <div class="col-xs-12 col-sm-6 col-md-6 col-lg-4"></div>
        ... 
        <!-- Bootstrap can manage with only 1 .row -->
    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀