-1

我想将图像分配给 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>";
}
4

6 回答 6

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>";
}
于 2013-09-30T08:16:49.857 回答
1

要么你分配 $var = "img src="'your/pathto/image.ext'";

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

并在 html img 代码中回显

第二种方法更可取

于 2013-09-30T08:10:11.673 回答
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>";
}
于 2013-09-30T08:14:38.303 回答
0

用这个:

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

假设$value您的图像名称带有图像扩展名。

于 2013-09-30T08:08:55.197 回答
-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."'>";
       }
     }
 ?>
于 2016-12-10T12:08:14.190 回答
-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=""/>
于 2017-11-13T09:09:36.573 回答