简体   繁体   中英

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..

Now what im doing is dynamically adding img tags for each row using the following code:

$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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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