在php中显示同一div中的不同图像

时间:2015-09-21 05:22:18

标签: php

我想在col1 div中显示第一个图像,标题和描述,在col3中显示第二个,依此类推 但在第一张图片中重复所有div。如何解决这个问题

<?php

include('connection.php');
$perPage=1;
$i=1;
if(isset($_REQUEST['act']) && trim($_REQUEST['act']=='load_data')){
     $page=1;
    if(!empty($_GET["page"])) {
$page = $_GET["page"];
}

$start = ($page-1)*$perPage;
if($start < 0) $start = 0;


    $msg='';
    $q="SELECT * FROM addimages  order by id desc limit $start,$perPage  ";
    $res = mysql_query($q);
    $row = mysql_fetch_array($res);
    $id = $row['art_id'];
    $qe="select banner from images where id=$id";
    $rs=mysql_query($qe);
    $name=mysql_fetch_array($rs);
    //$id=$row['id'];
    //$no=mysql_num_rows($res);

    if(!$row==""){

    $msg .= "<div class='article_index' id='".$row["art_id"]."'><div class='article banner_add'><a href='#'><img height='220'  src='./uploads/" . $name['banner'] . "' /></a></div>";

    $msg .="    <div class='post_main' >
            <div class='col1'>
            <div class='post_img'><a href='#'><img class='lazy' data-original='./uploads/" . $row['image'] . "' width='633' height='441' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
            </div>
            <div class='post_contant_main'>
            <div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
            <div class='post_contant'>".$row['desc']."</div>
            </div>
            </div>";

    $msg .="        <div class='col3'>
            <div class='post_img'><a href='#'><img class='lazy' width='299' height='191' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
            </div>
            <div class='post_contant_main'>
            <div class='post_title post_rtitle'><h2><a href='#'>".$row['title']."</a></h2></div>
            </div>
            </div>
            <div class='col3'>
            <div class='post_img'><a href='#'><img class='lazy' width='299' height='191' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
            </div>
            <div class='post_contant_main'>
            <div class='post_title post_rtitle'><h2><a href='#'>".$row['title']."</a></h2></div>
            </div>
            </div>
            <div class='col2'>
            <div class='post_img'><a href='#'><img class='lazy' width='461' height='300' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
            </div>
            <div class='post_contant_main'>
            <div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
            <div class='post_contant'>".$row['desc']."</div>
            </div>
            </div>
            <div class='col2'>
            <div class='post_img'><a href='#'><img class='lazy' width='461' height='300' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
            </div>
            <div class='post_contant_main'>
            <div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
            <div class='post_contant'>".$row['desc']."</div>
            </div>
            </div>
            </div>
    </div>

    ";
        }

    $msg .="<a class='next' href='#'></a>
        <input type='hidden' id='pageno' name='pageno' value=''>";
    echo $msg;



 }
?>    

我想将行数组增加到下一个id并显示其内容 我正在使用无限滚动插件

1 个答案:

答案 0 :(得分:1)

你只获取一个顶行。如果你想获得所有行,你需要循环思考。

while ($row = $result->fetch_row()) {

$msg .="    <div class='post_main' >
            <div class='col1'>
            <div class='post_img'><a href='#'><img class='lazy' data-original='./uploads/" . $row['image'] . "' width='633' height='441' src='./uploads/" . $row['image'] . "' style='display: inline;' /></a>
            </div>
            <div class='post_contant_main'>
            <div class='post_title'><h2><a href='#'>".$row['title']."</a></h2></div>
            <div class='post_contant'>".$row['desc']."</div>
            </div>
            </div>";

}