The function has no access to global variables unless you either pass it to the function or define it as global.
Either:
Code:
<?php
$dbh = mysql_connect ($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($mydb);
function list($title){
global $dbh;
$query = "SELECT * FROM table t WHERE t.title = '$title' ORDER BY t.year, t.last";
$result = mysql_query($query,$dbh) or die(mysql_error());
...
}
list("Most Valuable Player");
list("Rookie of the Year");
?>
or
Code:
<?php
$dbh = mysql_connect ($host, $user, $pass) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($mydb);
function list($title,$dbh){
$query = "SELECT * FROM table t WHERE t.title = '$title' ORDER BY t.year, t.last";
$result = mysql_query($query,$dbh) or die(mysql_error());
...
}
list("Most Valuable Player",$dbh);
list("Rookie of the Year",$dbh);
?>