Can anyone explain what the $PHP_SELF global variable does in the following script?

$db = mysql_connect("localhost", "root");
$result = mysql_query("SELECT * FROM employees",$db);
if ($myrow = mysql_fetch_array($result)) {
do {
printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $myrow["id"],
$myrow["first"], $myrow["last"]);
} while ($myrow = mysql_fetch_array($result));
} else {
echo "Sorry, no records were found!";

PHP_SELF is a variable that returns the current script being executed. This variable returns the name and path of the current file (from the root folder).

Let's say the code you posted above is on a file named 'test.php' and that the URL to that file (which you are currently executing) is $PHP_SELF then equals "/somefolder/test.php".

In your printf() function you have: <a href="%s"...> that first %s is replaced with the value of $PHP_SELF