php
  • arrays
  • html5
  • sqlite
  • 2014-11-25 34 views 0 likes 
    0

    我試圖顯示一個圖像(或更確切地說是一個圖像的鏈接)存儲在數據庫中,我想讓圖像顯示只有當鏈接設置爲數據庫。 當前,如果未設置鏈接(值爲空),則會顯示鏈接斷開。顯示圖像,如果它在數據庫中設置

    有沒有辦法,例如使用if語句和回顯HTML代碼? 事情是這樣的: (該值已在您使用<?php兩次這個例子:)

    <?php 
         if(isset($current['image']) { 
          echo "<img src='<?php echo $current['image']; 
        ?>' class='left' style='max-height:20em; max-width:15em; margin-right:1em; margin-top:0;'})"> 
    
    +0

    是的,這肯定是可能的,不要忘了結尾大括號壽。 – Jordy 2014-11-25 13:13:34

    +0

    你的代碼是可以的,只能放置結束的大括號 – 2014-11-25 13:15:07

    回答

    0

    沒關係,明白了。 - 溶液:

    <?php if(isset($current['image'])): ?><img src="<?php echo $current['image']; ?>" class="left" style="max-height:20em; max-width:15em; margin-right:1em; margin-top:0;})"> 
        <?php endif; ?> 
    
    0

    fecthed到數組$現在,你有引號,括號問題等

    <?php 
    
    if (!empty($current['image'])) { 
        echo "<img src='" . $current['image'] . "' class='left' style='max-height:20em; max-width:15em; margin-right:1em; margin-top:0;'>"; 
    } else { 
        // here you can write for example default no-image image or whatever yo want, if you want 
    } 
    
    0
    <?php 
        if(isset($current['image'])) { 
    
        ?> 
        <img src='<?php echo $current['image'];?>' class='left' style='max-height:20em; max-width:15em;   
    
    
         margin-right:1em; margin-top:0;'> 
        <?php 
        } 
        ?> 
    
    相關問題