Question: I have webpages with URL <http://siteurl/directory/onemore/>$fileID.php 
I am trying to extract just the $fileID and after that use 

```
$query = $mysqli->query("SELECT * FROM tablename WHERE ID = $fileID");
$rows = mysqli_fetch_array($query);
$hits = $rows['HITS'];
$hits = $hits + 1;
$query = $mysqli->query("UPDATE tablename SET HITS = $hits WHERE ID = $fileID");
echo 'Total hits on page'.$hits.'';

```

I can't figure out how to get just the $fileID part and wanted to ask is the rest of my procedure correct? 

**EDIT**

With the code above hits get stuck at one. I was thinking that after each page refresh they will update to +1.

Answer: 
You can determine the $fileId like this:

```
/* $_SERVER['PHP_SELF'] results to e.g. '/directory/onemore/5.php' */
/* basename(...) results to e.g. '5.php' */
$fileName = basename($_SERVER['PHP_SELF']);
/* take the text before the last occurrence of '.' */
$fileID = substr($fileName, 0, strrpos($fileName, '.'));

$query = $mysqli->query("UPDATE tablename SET HITS = HITS + 1 WHERE ID = $fileID");

$query = $mysqli->query("SELECT * FROM tablename WHERE ID = $fileID");
$rows = mysqli_fetch_array($query);
$hits = $rows['HITS'];
echo 'Total hits on page'.$hits.'';

```
If you don't need to print the hits every time, you can increment it in a single query which is a bit more clear and efficient.

```
UPDATE tablename SET hits = hits + 1 WHERE id = $fileID

```