retrieving data from database (newbie)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
i shot love
Forum Newbie
Posts: 3
Joined: Fri Sep 15, 2006 12:22 am

retrieving data from database (newbie)

Post 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?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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".
xfuture
Forum Newbie
Posts: 6
Joined: Wed Sep 13, 2006 2:27 am

Re: retrieving data from database (newbie)

Post 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...
Post Reply