Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用count PHP创建图像文件_Php_Mysqli - Fatal编程技术网

使用count PHP创建图像文件

使用count PHP创建图像文件,php,mysqli,Php,Mysqli,对于所有记录,我的代码循环遍历它们,依次显示它们。现在,我想为它们中的每一个添加一个图像 要做到这一点,我将使用文件路径not BLOB,因为我不能为这个项目 到目前为止,我已经在下面发布了代码,但我正在努力实现count函数,因为我希望每次增加文件的数量。我的文件存储为images/Starter1.jpg、images/Starter2.jpg等 <div id = "starters"> <p class = "big"> Starters </p&g

对于所有记录,我的代码循环遍历它们,依次显示它们。现在,我想为它们中的每一个添加一个图像

要做到这一点,我将使用文件路径not BLOB,因为我不能为这个项目

到目前为止,我已经在下面发布了代码,但我正在努力实现count函数,因为我希望每次增加文件的数量。我的文件存储为images/Starter1.jpg、images/Starter2.jpg等

<div id = "starters">
    <p class = "big"> Starters </p>
    <?php
    while($row = mysqli_fetch_assoc($result_starters)){
        $count = 0; 
        echo "<div id = item> ".
        "<p>".
        "<b>Name: </b> ". $row["name"].
        "<img src = images/Starter".$count.".jpg width = 100px, height = 100px>".
        "<br><br><b>Price: </b>&pound;". $row["price"].
        "<br><br><a href=menuInfo.php?ID=".$row["productID"]."><button type = button> See more details </button></a>".
        "<br><br><button type = button> Add to favourites </button>".
        "<br><br><button type = button> Add to basket </button>".   
        "</p>". 
        "</div>";
        $count = $count + 1;
    }
    ?>
</div> <!-- For starters --> 

起动器


在每次迭代中,您将$count变量放回0。“初始化”循环外的变量,增量将起作用

您还可以用比
$count=$count+1更合适的方式递增+$count

别忘了在html属性中加引号

<div id = "starters">
    <p class = "big"> Starters </p>
    <?php
    $count = 0; 
    while($row = mysqli_fetch_assoc($result_starters)){
        ?>
        <div id ="item">
            <p>
                <b>Name: </b><?php echo $row["name"]; ?>
                <img src="images/Starter<?php echo $count; ?>.jpg" width="100px" height="100px">
                <br><br><b>Price: </b>&pound;<?php echo $row["price"]; ?>
                <br><br><a href="menuInfo.php?ID=<?php echo $row["productID"]; ?>"><button type="button"> See more details </button></a>
                <br><br><button type="button"> Add to favourites </button>
                <br><br><button type="button"> Add to basket </button>
            </p>
        </div>
    <?php
        ++$count;
    }
    ?>
</div> <!-- For starters --> 

起动器

姓名: .jpg“width=“100px”height=“100px”>

价格:&英镑;



添加到收藏夹

加入篮子


+$count
是一种更好的编写
$count=$count+1;
@D4V1D的方法,起初我不想让它修复它,但现在你说了,我编辑了我的帖子,谢谢;-)别忘了在html属性中为img加上src的引号-我想你看到了我的评论;-)@Fred ii-我必须说是的
:-P
谢谢!我可以我不知道出了什么问题!@D4V1D也谢谢你。我在想你用JavaScript做这件事的简洁方法,当这种方法不起作用时,我只是写了很长的一段时间,因为
图像
文件夹之前缺少一个引号,这将作为一个解析错误而出错。