Get result from database using a function SafDBFunc

<?
//Get result from database using a function SafDBFunc
//From following function you will get an output staff name
//To get the staff name you need to pass some veribles like table name ($tablename) and databse conncetion ($db)
//and also the staff number ($staffid), it will go inside the function and open the databse in given table for the record
function TakeStaffNameSafDBFunc($tablename,$db,$staffid){
$sql = "SELECT * FROM $tablename where staffid='$staffid'";
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
if (
mysql_num_rows($result_a)) {
$data = mysql_fetch_object($result);
$fldStaffName = $data->fldStaffName;
}
return
$fldStaffName;
}
?>