Page 1 of 1

retrieving data from database (newbie)

Posted: Fri Sep 15, 2006 12:35 am
by i shot love
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.

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 );
?>
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?

Posted: Fri Sep 15, 2006 3:35 am
by aaronhall
I'd explain it to you here, but there are plenty of other sites that already have. You have two things to learn: basic MySQL query structure, and the PHP mysql functions. http://www.freewebmasterhelp.com/tutorials/phpmysql is the first thing I found when I googled "php mysql tutorial".

Re: retrieving data from database (newbie)

Posted: Fri Sep 15, 2006 3:39 am
by xfuture
i shot love wrote:
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?


I guess you need a "SELECT" SQL query

which like SELECT * FROM album where Artist = "Metallica" and Album = "Master Of Puppets";

please note that make sure your Character is in the Capital form or vise..

after that.. do a fetch array...