CODE
mysql_connect(localhost,$username,$password);
/* Connect to the MySQL thing on localhost, using the specified username and password */
@mysql_select_db($database) or die( "Unable to select database");
/* Select a certain database. If unable to, then stop and print an error message */
$result=mysql_query($query);
/* The $result variable is used to store the result of the query. If you're inserting data or doing some other query that gives no results, then omit the '$result=' */
mysql_close();
/* Close the connection. Having too many MySQL connections open on a server could impact performance. */
I'll assume that you know how to write a MySQL query.
If not,
http://dev.mysql.com/doc/refman/5.0/en/tutorial.html-----Edit-----
More on how to use the table stored in $result :
CODE
$num=mysql_numrows($result);
/* Find the number of rows in $result and store it in $num */
$variable=mysql_result($result,$i,"fieldname");
/* Get the value stored in $result, in row $i, in the column named 'fieldname' and assign it to $variable */