1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP PHP form with counter (not site visit counter)

Discussion in 'Web Development' started by xtremewriter, Nov 5, 2011.

  1. xtremewriter

    xtremewriter New Member

    Hi!
    Disclosure (I don't know much about PHP - all my work is on the front end). I'm trying to build a form for this non-profit - pet-connections.org.

    But - the form is the easy part - I can do that. Ok, actually, I could find a lot of scripts that do that.

    What I need is a form script with first and last name, zip, email, a checkbox marking that they'd like to receive emails and a submit button. But then - my client is requesting a counter similar to on this site: Volunteer Reading, Tutoring & Mentoring | Volunteering to Help Kids & Education | United Way - where it says how many people have pledged so far.

    I can't seem to find any scripts out there that do this. Can anyone help me out? Or if you can create something fairly quickly (I don't need design - just the HTML to place within DIVs, etc.) I would pay! I would also give you all the database info, etc.

    Do I sound desperate? Ha...yeh..

    Thanks in advance for any help.
     
  2. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    Since you are sending the form info to the database, try a Query using
    SQL: COUNT Function - then echo the result to the screen.

    SQL: COUNT Function
    The COUNT function returns the number of rows in a query.
    The syntax for the COUNT function is:

    SELECT COUNT(expression)
    FROM tables
    WHERE predicates;

    Note:
    The COUNT function will only count those records in which the field in the brackets is NOT NULL.
    (they need to have data in them to be counted.)


    For example, if you have a table called Signups:
    The table contains all the data from your Form.
    The Check Box is a column called receive_emails

    So far 5 people submitted the form but only 3 checked the Box to Receive Emails. (the form sends "Yes" to the database)
    The result for this query will return 3 because there are three people who have checked the box and in the table row related to them has a "yes". The other 2 are NULL.

    Select COUNT(Receive_Emails) from Signups;

    Now you can take that result and echo it to the screen, it will increment up, every time someone checks the Box and submits the Form.

    You can use this (expression) as required to display what ever you need.
    If you select say Last_Name the output would be 5, as you have 5 last names in the table.

    This should point you in the right direction. Let us know how it goes so others can benefit.