简体   繁体   English

PHP / MYSQL使用while循环获取当前行,然后从第1列输出数据,然后对以下行进行相同的操作

[英]PHP/MYSQL using while loop to get current row then output data from column 1, then proceed to do the same for the following rows

Ok so i have a mysql database with a table called fotf_images, which as you can guess stores image information like location, name, etc.. 好的,我有一个名为fotf_images的表的mysql数据库,您可以猜测该表存储了位置,名称等图像信息。

Now what im doing is dynamically adding img tags for each row using the following code: 现在,即时通讯正在使用以下代码为每行动态添加img标签:

$count = 0;
                        $currentcount = $count; //gets row by count number

                        while($count < $numrows)
                        {
                            echo '<img src="" width="250" height="200" class="fotfimage" vspace="2">&nbsp;&nbsp;&nbsp;&nbsp;';

                            $count++;
                            if($count == $numrows)
                            {
                                break;  
                            }

                        }

Now what i need to do is actually display the image based on the data in the currently selected rows column 1. So for example, if there is 3 rows, then my current code will add 3 img tags, i then need to add the src for each img tag based on the field value for each rows' column 1 which stores its location. 现在,我需要做的实际上是基于当前选定的行第1列中的数据显示图像。因此,例如,如果有3行,那么我当前的代码将添加3个img标签,然后我需要添加src基于每个行的列1的字段值存储每个img标签,该列存储其位置。

Any help on this would be greatly appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

I'm not sure if I understand you right: The source of each picture is stored in the first column? 我不确定我是否理解正确:每张图片的来源都存储在第一列中? If I got this right maybe following code will help you. 如果我做对了,也许下面的代码会为您提供帮助。

<?php


$result = mysql_query("SELECT * FROM fotf_images");

while ($row = mysql_fetch_array($result)) {
     $columnId = 0;
     echo '<img src="'.$row[{$columnId}].'" width="250" height="200" class="fotfimage" vspace="2">';

}
?>

Something like this ? 像这样吗?

$my_array = mysql_fetch_row ($result)
echo '<img src="'.$my_array[1].'" width="250" height="200" class="fotfimage" vspace="2">&nbsp;&nbsp;&nbsp;&nbsp;';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM