PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Totaling all entries from a specific field as a counter

  1. websitedesignercharlotte
    Member

    I am working on a site called MyFish.com that is a fishing and biological data log. I have two dropdown fields on this form http://www.myfish.com/enter-a-fishing-trip-log/ (user:demofisherman / pass:demo) that I want to total and display in a text widget as a counter in the sidebar.

    The fields are fish caught and fish released which are both numerical dropdowns.. Each form submission has a variable amount of fish caught and released.
    Example:
    fisherman 1: 15 fish caught | 10 released
    fisherman 2: 25 fish caught | 12 released
    I want to extract the meta for ALL entries for these specific fields on this one form and display a running total as users enter fish in the log. Is this possible using the current hooks, filters and a little php? I have a functioning "counter" working on the thank you page and in the sidebar by passing two variables in the url (fishcount and fishreleased) to the thank you page and running the following code in the post. The code updates a simple text document and uses similar code to echo it in the sidebar in a text widget.

    Thank you for logging your <?php $fishcount=$_GET["fishcount"]; echo $fishcount; ?> fish!
    
    Total fish logged on MYFish.com:
    <?php
    $fishcount=$_GET["fishcount"];
    	if (file_exists('count_file.txt'))
    	{
    		$fil = fopen('count_file.txt', r);
    		$dat = fread($fil, filesize('count_file.txt'));
    		echo $dat+$fishcount;
    		fclose($fil);
    		$fil = fopen('count_file.txt', w);
    		fwrite($fil, $dat+$fishcount);
    	}
    
    	else
    	{
    		$fil = fopen('count_file.txt', w);
    		fwrite($fil, 1);
    		echo '1';
    		fclose($fil);
    	}
    ?>
    
    Total fish Released:
    <?php
    $fishreleased=$_GET["fishreleased"];
    	if (file_exists('count_released.txt'))
    	{
    		$fil = fopen('count_released.txt', r);
    		$dat = fread($fil, filesize('count_file.txt'));
    		echo $dat+$fishcount;
    		fclose($fil);
    		$fil = fopen('count_released.txt', w);
    		fwrite($fil, $dat+$fishreleased);
    	}
    
    	else
    	{
    		$fil = fopen('count_released.txt', w);
    		fwrite($fil, 1);
    		echo '1';
    		fclose($fil);
    	}
    ?>

    I know this method presents a lot of problems and querying the actual entries is the correct way. How do I do this?

    Posted 12 years ago on Friday November 18, 2011 | Permalink
  2. This should be possible. The Gravity Forms entry data is stored in your WordPress database. So it can be queried and parsed just like any data. This wouldn't require Gravity Forms hooks/filters because you aren't actually changing Gravity Forms. You would be displaying data outside of Gravity Forms.

    Here is a post that discusses how to write custom code to get a count of the total number of entries for a form:

    http://www.gravityhelp.com/forums/topic/display-entries-count-on-site

    You could start with that, then you would have to customize it so rather than getting an entry count you get a count of field selections. It's a bit more complex for sure.

    Give it a shot, and if you need further assistance after giving it a try... we can take a look and help you out with the code.

    Posted 12 years ago on Friday November 18, 2011 | Permalink
  3. websitedesignercharlotte
    Member

    Thanks so much Carl for your timely reply and I will post only on this thread. Sorry about the duplicate. I read all forum posts including the one above referencing totaling poll submissions but never really found where to begin with actually totaling counts from one specific field. The code in the article above references the total submissions of the form but not the ability to sum as a better definition all entries from one field.
    Example:
    Entry one on dropdown field "Fish Caught" - 10
    Entry two on dropdown field "Fish Caught" - 20

    Query should select all entries from form 1 field fish caught sum them and echo total (30) fish caught. See http://www.myfish.com/all-logged-fish/ and view the sidebar for desired result. See http://www.myfish.com/enter-a-fishing-trip-log/ for the form used. Thank you so much for your help.

    Posted 12 years ago on Friday November 18, 2011 | Permalink
  4. Yes, i'm aware the example code used the total submissions of the form. It's just an example. You'll need to take that code and customize it to suit your needs. Or work with a WordPress consultant to create the customization for you if you aren't sure how to properly query the data.

    Posted 12 years ago on Friday November 18, 2011 | Permalink

This topic has been resolved and has been closed to new replies.