retrieving data from database (newbie)
Posted: Fri Sep 15, 2006 12:35 am
Please use the Code and PHP tags when posting program code.
Ok first, my goal is to create a website reviewing music. i want to allow users to rate songs and albums on a number scale. i installed XAMPP and have created a database with phpMyAdmin and threw a few entries in. i'm just testing things out and trying to learn this stuff as i go along so please be patient, i have no idea what i'm doing. i used the following code to establish a connection with the database and from what i see, it works because i got the "Successfully selected database "ratings" " message.
i have 3 fields in the database, "Artist", "Album", and "Rating". i have added 2 albums just for sample data. say i wanted to print the rating for Metallica's "Master Of Puppets" album (10), how would i go about doing that?
Ok first, my goal is to create a website reviewing music. i want to allow users to rate songs and albums on a number scale. i installed XAMPP and have created a database with phpMyAdmin and threw a few entries in. i'm just testing things out and trying to learn this stuff as i go along so please be patient, i have no idea what i'm doing. i used the following code to establish a connection with the database and from what i see, it works because i got the "Successfully selected database "ratings" " message.
Code: Select all
<?php
$db = "ratings";
$link = mysql_connect( "localhost");
if ( ! $link )
die( "Couldn't connect to MySQL" );
print "Successfully connected to server<P>";
mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<P>";
mysql_close( $link );
?>