PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
However, when I try to increment $totalqueries from inside a function it does not incremement, thus when echoing $totalqueries at the bottom of the page it will only show the queries that were executed on the page (or included page) itself, and not the ones called from various functions that query the database.
Question: How can I increment a global variable from within a function, because:
Say I have a file index.php, which has 4 functions that each do database queries, I want to add up all queries executed across all 4 functions, then display that value on the index.php page. By doing global $totalqueries; in each function I am redeclaring it over and over, what I need is 1 global that I can increment from within various functions.
waradmin wrote:By doing global $totalqueries; in each function I am redeclaring it over and over, what I need is 1 global that I can increment from within various functions.
The "global" keyword will not recreate the global variable if it already exists. You can use global repeatedly.