Using PHP to create XHTML lists from MySQL data

Database data tends to be in rows. Lists are in rows. The two match fairly well.

The first stage is to get the data from the database.

The second stage is to get the data into variables.

the UL element needs to be set up with a loop to generate list items something like this:

            
echo "<ul>";                    
while ($cdrow=mysql_fetch_array($cdresult)) {
    $cdTitle=$cdrow[cdTitle];
    $cdArtist=$cdrow[cdArtist];
    $cdPrice=$cdrow[cdPrice];
    echo "<li>$cdTitle, $cdArtist, $cdPrice</li>";	
}
echo "</ul>";
        

Try this by saving firstmysqlpage.php as firstmysqllist.php and altering the code based on the above.

Upload the page and you should find the titles displayed in a list. You could add the other data. Lists don't really allow you good structure for the data but you could improve it a bit.

submit to reddit Delicious Tweet