Displaying data SELECTed from MySQL

Using firstmysqlpage.php this is how you can show the results of the query:

            
while ($cdrow=mysql_fetch_array($cdresult)) {
    echo "<pre>";                
    print_r($cdrow);
    echo "</pre>";
}            
        

The first line sets up a PHP while loop. It will keep going for as long as data comes from the server. The function mysql_fetch_array() gets the next row of data from the server. $cdresult is the pointer to the results of the SELECT query from the last page. So each time around this loop the server sends the next row/record and it gets stored in $cdrow.

The three lines of code inside the loop are there just to print the content of each row.

A better way would be to replace the print_r with some more attractive XHTML:

            
while ($cdrow=mysql_fetch_array($cdresult)) {
    $cdTitle=$cdrow[cdTitle];
    $cdArtist=$cdrow[cdArtist];
    $cdPrice=$cdrow[cdPrice];
    echo "<p>The CD is $cdTitle by $cdArtist and sells for £$cdPrice.</p>";                
}        
        

The variable names do not need to be the same as the field names but it does make it easier for you if they are.

If the £ sign has a weird capital A before it don't panic just replace it with &pound; in the code (its because of the way it copied and pasted combined with your server)

submit to reddit Delicious Tweet