How to count number of towns in registrations

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
bambinou
Veteran Member
Posts: 163
Joined: 2013-02-01 15:09

How to count number of towns in registrations

Post by bambinou » 2013-06-27 09:17

Hi,

I would like to know if it is possible to create a table that tells us the number of time a town(from the pr-epopulated town drop down menu) has been registered.

IE:
I have a form with pre-populated town names. I would really like to see:

Town 1 = 34 people
Town 2 = 56 people
Town 3 = 57 people
Town 4 = 65 people

At the moment I have a database with:

ID | Town | Surname | Last Name | Email

With my research it seems that something like this could work:
"SELECT count(city) as count, city FROM table_name GROUP BY city ORDER BY count"

But where to actually put it in app gini? Any idea please?

Also how to re-use the same field into another table so I can output all the towns and their GROUP values?

Thank you.

Ben

wplim
Veteran Member
Posts: 36
Joined: 2013-01-17 22:42

Re: How to count number of towns in registrations

Post by wplim » 2013-06-28 05:59

You may add a field say Count in another table say TownList. then add the following function in _global.php

Code: Select all

	function updatePeopleCountByTown($TownID){
		// update people registered by Town
		$TownID=makeSafe($TownID);
		$Count=sqlValue("select count(ID) from registration_table_name where Town='$TownID' ");
		sql("update CityList set Count='$Count' where Town ='$TownID' ", $eo);
	}
Then call this function in registration_table_name hook file (ref: http://bigprof.com/appgini/help/advance ... ific-hooks)
within the hook functions tablename_after_insert() and tablename_after_update()

Hope this help.

bambinou
Veteran Member
Posts: 163
Joined: 2013-02-01 15:09

Re: How to count number of towns in registrations

Post by bambinou » 2013-06-28 09:13

Hi wplim,

Thank you so much for your reply.

I would like to know what is the difference between Makesafe and Mysql_real_escapte_string please? Are they different? I cannot really find much good info on Makesafe.

Regarding the graphs, I have just highcharts, it was a bit of a pain to setup but it works great.

Thanks for your help,

ben

wplim
Veteran Member
Posts: 36
Joined: 2013-01-17 22:42

Re: How to count number of towns in registrations

Post by wplim » 2013-06-29 05:35

Hi Ben,

I think Ahmad created the makesafe function, which make use of Mysql_real_escapte_string function to prepares variables to be used safely inside SQL queries.

WP

bambinou
Veteran Member
Posts: 163
Joined: 2013-02-01 15:09

Re: How to count number of towns in registrations

Post by bambinou » 2013-06-29 07:35

Hi WPslim,

Thank you so much for the reply :-) I get it now.

Thanks!

Regards,

Ben

User avatar
toconnell
Veteran Member
Posts: 204
Joined: 2013-04-09 19:29
Location: Oklahoma City, OK
Contact:

Re: How to count number of towns in registrations

Post by toconnell » 2013-07-02 19:00

Your going beyond what this program is intended for.. even though you can do it..
I would reccomend for reporting things like that you get REPORTICO.. try reportico.org to download the software.. under $30 and there is a free version and it is pretty robust working with my APPGini database.

Thanks, Tina
Tina O'Connell
Web Dev & Appgini FAN

Post Reply