php - 如何水平显示两个图像?

标签 php css

我有一个问题,需要答案。如何自动将 2 个图像水平放置。

我想我会使用一些 if(1 ==%3)? 在示例图片中,我真的很喜欢水平放置 2 张图像,但不知道该怎么做?

这是我所做的:

for($i=0; $rows = $results->fetch(); $i++){
    if($dsds=='Commissoner'){
    echo $rows['prog_id'].$rows['prog_id'].'  '.$rows['prog_name'].'  =  '.$rows['votes'];

    }else {
//this is the part where I put a css
    style='margin-left:44px;'><div class='box_img2' style='margin-right:10px;' >";
    echo '<img src="candidates/images/'.$rows['image'].'" width="70" height="80px" />'.',&nbsp;'.'<br>'.$rows['lastname'].',&nbsp;'.$rows['firstname'].'<br>'.'&nbsp;=&nbsp;'.$rows['votes'];
    echo '<br>';
            }
    $sdsd=$dsada    
        ?>
        <img  src="candidates/images/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>
        <?php 
            if ($rows['votes']==0){
        echo "<br>";}
            else {
            echo(100*round($rows['votes']/($sdsd),2)); ?>%<br>
                        <?php
                            }
                            echo '</div>';
                        }

                        ?>

Sample of my problem

这是我的 CSS:

.row:before, .row:after { clear:both; }
.row{
 display: block;

}

.box_img2 {
        float: left;
        /*margin-right:85px;*/
        text-align:center;
    }
    .box_img2 img { /* if you want it centered */
     display:block;

        display: inline-block;
    }

这是我的全部代码:

<?php
      include('../connection/connect.php');
        $result = $db->prepare("SELECT * FROM candposition ORDER BY posid ASC");
                $result->bindParam(':userid', $res);
                $result->execute();
                for($i=0; $row = $result->fetch(); $i++){
                $dsds=$row['posid'];
                $resulta = $db->prepare("SELECT sum(votes) FROM candidates WHERE posid= :a");
                $resulta->bindParam(':a', $dsds);
                $resulta->execute();
                for($i=0; $rowa = $resulta->fetch(); $i++){
                    $dsada=$rowa['sum(votes)'];
                }
                    echo '<div style="margin-top: 18px;">';
                    echo '<strong>'.$row['pos_name'].'&nbsp;'.'</strong><br>';

                    $results = $db->prepare("SELECT * FROM candidates,student WHERE candidates.idno=student.idno AND candidates.syearid = '$no'AND posid = :a ORDER BY votes DESC");
                    $results->bindParam(':a', $dsds);
                    $results->execute();
                    for($i=0; $rows = $results->fetch(); $i++){
                        if($dsds=='Commissoner'){
                        echo $rows['prog_id'].$rows['prog_id'].'&nbsp;&nbsp;'.$rows['prog_name'].'&nbsp;&nbsp;=&nbsp;&nbsp;'.$rows['votes'];
                                }else {

//this is the part 
                            echo'<?php $src=array("candidates/images/".$rows["image"]); for($i=0;$i<3;$i++){ ?>';
                            echo '<img src="candidates/images<?php echo .$src[$i];?>" class="image-inner" />';}
                        $sdsd=$dsada    
                            ?>
        <!--    <img  src="candidates/images/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>-->
                    <?php 
                        if ($rows['votes']==0){
                            echo "<br>";}
                                else {
                            //  echo(100*round($rows['votes']/($sdsd),2)); /
                            /*?>%<br>*/
    /*<?php
                            }
                            echo '</div>';*/
                        }
                        }
                        ?>  
                        <?php
                }
                ?>

最佳答案

这是我可以使用 php 解释的最简单的方法。希望这能帮助您理解

.image-inner {
  position: relative;
  width: 150px;
  display: inline-block;
}
<?php
  $src = array(
    'http://www.google.com/logos/2008/de_doodle4google08.gif', 
    'http://www.google.com/logos/2012/d4g_poland12-hp.jpg', 
    'http://www.google.com/logos/2011/colombia-independenceday11-hp.jpg'
  );
  for($i = 0; $i < 3; $i++)
  {
    echo "<img src='{$src[$i]}' class='image-inner' />";
  }
?>

关于php - 如何水平显示两个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34805224/

相关文章:

php - SQLSTATE[HY093] : Invalid parameter number INSERT

php - MySQL比较日期不返回结果

php - 处理连续的 Ajax 请求 - JQUERY

CSS3 transitions 想要添加颜色并将其淡化

php - Android 允许将多个文件上传(最大 150 MB)到 PHP 服务器

php - 使用 cakephp save 在 mysql 数据库中保存十进制值时出现问题

css - 移动网站 - 根本不滚动

html - CSS 媒体查询和 div 背景颜色

html - 使字体高度为视口(viewport)高度的大小

带 Angular 的 HTML 矩形框