Basically I have a foreach loop bringing in data from an array of products in a database which include price etc.. The data is pulled down first by a simple mySQL SELECT query. Which is then stored in an associative array.
I want to count the number of items that get displayed on the page. I know how to count the items in the array but I’m going to be filtering which ones get displayed on the page via urls and would like to just count how many get actually displayed.
I had the idea to just have a variable and + 1 everytime the foreach loop ran but the trouble is I need to echo the number before the loop runs.
Here is my loop:
<h2>Title</h2><h5><? echo $numberofproducts; ?> products</h5>
<?
$numberofproducts == 0;
foreach(get_products() as $product){
$numberofproducts++;
// display product info
?>
Is there a way to update the h5 tag after the loop has finished running via AJAX? Without the need for another php file with one line in it?
Just go like this: