vendredi 8 mai 2015

How to I display a div for each row of data in a database?

I have a database that stores information of an item including an image source path, descriptions etc. Currently the data is static, as shown in the code snippet below. Basically I need to output a new 'thumbnail' for each row of data in the table. I think this is done by a for loop, however I'm not sure how to implement this. Thank you.

<div class='panel-heading' contenteditable='false'>Your items for sale</div>
                <div class='panel-body'>
                  <div class='row'>
                <div class='col-md-4'>
                    <div class='thumbnail'>
                        <img alt='300x200' src='http://ift.tt/1DWdOf6'>
                        <div class='caption'>
                            <h3>
                                Rover
                            </h3>
                            <p>
                                Cocker Spaniel who loves treats.
                            </p>
                            <p>

                            </p>
                        </div>
                    </div>
                </div>
                <div class='col-md-4'>
                    <div class='thumbnail'>
                        <img alt='300x200' src='http://ift.tt/1H69CkA'>
                        <div class='caption'>
                            <h3>
                                Marmaduke
                            </h3>
                            <p>
                                Is just another friendly dog.
                            </p>
                            <p>

                            </p>
                        </div>
                    </div>
                </div>
                <div class='col-md-4'>
                    <div class='thumbnail'>
                        <img alt='300x200' src='http://ift.tt/1DWdOf8'>
                        <div class='caption'>
                            <h3>
                                Rocky
                            </h3>
                            <p>
                                Loves catnip and naps. Not fond of children.
                            </p>
                            <p>

                            </p>
                        </div>
                </div>

            </div>

         </div>
</div>

My attempt:

<?
$sql = "SELECT srcpath FROM images";
$res = mysql_query($sql) or die(mysql_error());

$result = mysql_query($sql);

echo '<div"><ul>';

while($fetch = mysql_fetch_array($result)){
$petname = $fetch ['username'];
echo '<li><P>' . $fetch['description'] .'</P>';
echo '<img src="'.$fetch['srcpath'].'" alt="" />';
echo '</li>';
}
echo '</ul></div>';

?>




Aucun commentaire:

Enregistrer un commentaire