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: 
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

```
Getting $fileID of the URL:
Have a look at [pathinfo()](http://php.net/manual/de/function.pathinfo.php) - this function extracts the URL in different parts 

In your case it would be:

```
$path_parts = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$fileID = $path_parts['filename']; 

```

Your update query will work, in case you only want to count without showing the new value, you could make it more simple - just increment HITS while updating the table row:

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

```