Other Applications 41
My Albums

My Albums

$host =  localhost ;
$user =  U
SERNAME
 ;
$pass =  P
ASSWORD
 ;
$database =  music ;
$query = "SELECT album, artist, year, rating FROM albums ORDER BY artist";
if ($sqlConnection = mysql_connect($host, $user, $pass)) {
if (mysql_select_db($database, $sqlConnection)) {
if ($queryResult = mysql_query($query, $sqlConnection)) {
while ($album = mysql_fetch_array($queryResult)) {
albumRow($album);
}
mysql_free_result($queryResult);
} else {
sqlProblem("Cannot perform query $query.");
}
} else {
sqlProblem("Cannot select database $database.");
}
mysql_close($sqlConnection);
} else {
sqlProblem("Problem connecting to $host.");
}
function sqlProblem($warning) {
$latestError = mysql_error();
echo "$warning ($latestError)\n";
}
function albumRow($albumInfo) {
$album = $albumInfo[ album ];
$artist = $albumInfo[ artist ];
$year = $albumInfo[ year ];
$rating = $albumInfo[ rating ];
echo "\t\t\t
";
echo "
";
echo "
\n";
}
?>
AlbumArtistYearRating
$album$artist$year$rating
The  mysql_connect() function connects your page to the database, the mysql_select_db()
function selects the database you want, and the mysql_query() function performs your query.
The  mysql_free_result()  function  tells  PHP  that  you're  finished  with  that  query  and  the
mysql_close() function tells PHP that you're finished with that connection.
The  important  parts  are  mysql_error(),  which  tells  you  the  last  error  that  occurred,  and
mysql_fetch_array(), which gives you the next row from the database. Items in the row can
be pulled out by their name.




  

Home

About Services Network Support FAQ Order Contact
 

Php MySQL Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved