2013-09-30 110 views
-1

我想在图像中的PHP脚本分配给一个变量,这样我可以使图像显得时,我想它,通过声明的变量。分配图像PHP变量

$FoodList = array_unique($FoodList); 
if (!empty($FoodList)) { 
    foreach ($FoodList as $key => $value) { 
     // The variable would go here, so that image would appear 
     //next to each variable 
     echo "<li>" . $value . "<li>"; 
    } 
    echo "</ul>"; 
} 
+2

表明我们的样本数据为您'$ foodList'阵列 –

+0

什么是你的'$ value'?图片来源? –

回答

0

使用此:

echo "<li><img src='path_of_image/".$value."'/><li>"; 

假设$value与图像的扩展图像的名称。

1

要么你分配 是$ var = “IMG SRC =” '你的/ pathto/image.ext'“;

$var = "your/pathto/image.ext"; 

和HTML代码IMG呼应它

第二种方法是多优选

+0

ext可能是jpeg,gif无论你的文件类型是什么 – jayadevkv

0
$FoodList=array_unique($FoodList); 
$img_path = 'images/example.jpg'; 
if(!empty($FoodList)) 
{ 
    foreach ($FoodList as $key => $value) 
{ 

    echo "<img src='$img_path' />"; 
    echo "<li>".$value."<li>"; 

} 
echo "</ul>"; 
} 
1
$FoodList = array_unique($FoodList); 

if(!empty($FoodList)) { 
    foreach ($FoodList as $key => $value) { 
     //The variable would go here, so that image would appear 
     //next to each variable 
     $value = "<li>"; 

     //Maybe you'll only display an image is a certain condition is met? If so, then... 
     if($condition == "parameter") { 
      $value .= "<img src='path/to/img' alt='img' />"; 
     } 

     $value .= "</li>"; 
     echo $value; 
     unset($value); 
    } 
    echo "</ul>"; 
} 
-1
<?php 

    $name="Adil"; 
    echo $name; 
    $path="FB_IMG_1465102989930.jpg"; 
    for($i=0;$i<44;$i++) 
    { 
     echo($i.'<br>')  ; 
     if($i==10) 
     { 
      echo ".$path."; 
      echo "<img src ='".$path."'>"; 
     } 
    } 
?> 
-1

请你的形象名称前插入空格: - 例子: -

$image_name="myphoto.jpg"; 

$image_path="./upload/ ".$image_name; 

这里我以后"./upload/(space)"

存储图像路径添加空格到您的MySQL数据库。

把它从你的HTML页面: -

<img src= '<?php echo $image_path;?>'width="200" height="200" alt=""/>