簡體   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

好的,我有一個名為fotf_images的表的mysql數據庫,您可以猜測該表存儲了位置,名稱等圖像信息。

現在,即時通訊正在使用以下代碼為每行動態添加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;  
                            }

                        }

現在,我需要做的實際上是基於當前選定的行第1列中的數據顯示圖像。因此,例如,如果有3行,那么我當前的代碼將添加3個img標簽,然后我需要添加src基於每個行的列1的字段值存儲每個img標簽,該列存儲其位置。

任何幫助,將不勝感激。 謝謝!

我不確定我是否理解正確:每張圖片的來源都存儲在第一列中? 如果我做對了,也許下面的代碼會為您提供幫助。

<?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">';

}
?>

像這樣嗎?

$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