Question: I have this **file.php** file that is doing a

```
SELECT 'NAME' FROM users WHERE CONDITION

```

I would like to keep track of the rows that have been served for every call.  

so I'd like to keep a counter for each row.

What is the most efficient way in **PHP** to update a counter for every row that was fetched?

Answer: 
you need to add an extra column for view/fetch count

```
SELECT          
    ...., views+1 as view
FROM table_name
WHERE ....

UPDATE table_name
SET views = views + 1
WHERE ...;

```

you can put it in a `Transaction`
You could always add a `fetched_at` column to that table, then update that if/when you fetch records:

```
UPDATE users SET fetched_at=UTC_TIMESTAMP() WHERE ...condition...

```

Then fetch as you would normally. You would apply an identical condition to both cases. Keep in mind that if you're using `JOIN` this might be much more difficult to implement.

If you need to keep a count, use an `INT` column:

```
UPDATE users SET fetched_count=fetched_count+1 WHERE ...condition...

```