2016-01-15 93 views
2

我有一個問題,需要一個答案。我如何自動將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 
       } 
       ?> 
+0

只要給 '位置:相對;'在CSS中,並給圖像一些寬度 –

+0

我應該在那裏放置?在排隊? – miming

+0

這裏是你的小提琴.. https://jsfiddle.net/adarsmohan76/cdvsw8hz/ –

回答

1

這是我可以解釋使用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' />"; 
 
    } 
 
?>

+0

先生?我應該在哪裏放置「candidates/images /'.$ rows ['image']。'?? – miming

+0

U可能會將它們放置爲像<?php echo'';?> –

+0

在php中有不同的輸出方式。或者使用echo來輸出img標籤,或者通過關閉php標籤並像往常一樣輸入img標籤來直接使用它們。 –

1

顯示器divs作爲inline-block像這樣:

#christmas_promotion_boxes div { 
    display: inline-block; 
} 

jsFiddle

+0

如果我在php中調用圖像,該怎麼辦? – miming