Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 MOD-Group
 MOD Add-On Forum (W/O Code)
 Country Count
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 4

mortioli
Average Member

United Kingdom
898 Posts

Posted - 29 March 2003 :  10:43:27  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
Hiya!

Just wondered if someone would be able to help me out...

I'm trying to list all the countries, with a number to show how many are from each. I have this code to do it:


Set rs = Server.CreateObject("ADODB.Recordset")
StrSql = "SELECT M.M_COUNTRY, " & _
         "COUNT(M.MEMBER_ID) AS M_COUNT " & _
         "FROM FORUM_MEMBERS M " & _
         "GROUP BY M.M_COUNTRY " & _
         "ORDER BY COUNT(M.MEMBER_ID) DESC;"
rs.Open StrSql, my_Conn
do until rs.eof
strCountryName = Trim(rs("M_COUNTRY"))
 if strCountryName = "" then strCountryName = "Unknown"
 Response.write "<font face=""" & strDefaultFontFace & """ size=""" & strDefaultFontSize & """ color=""" & strDefaultFontColor & """>" & strCountryName & " - <i>" & rs("M_COUNT") & "</i></font><br>"
rs.movenext
loop
rs.Close
set rs = nothing


But the trouble is, I'd like to be able to determine where I put each country count...eg, I could put UK in a table, USA somewhere else etc etc.

I came up with this code:


function getUSACount
	set rs = server.CreateObject("adodb.recordset")
	strSql = "SELECT COUNT(*) as USA" & strMemberTablePrefix & "MEMBERS WHERE M_COUNTRY = 'USA'"
	rs.Open strSql, my_Conn
	getUSACount = rs("USA")
	rs.Close
end function


...but it means I would have to write that out for each individual country.

My question is, would their be a way to get all the info, and then use (for example) USACOUNT to display the count for the USA etc etc

Sorry if it seems an odd explanation

Thanks for any help

mortioli
Average Member

United Kingdom
898 Posts

Posted - 01 April 2003 :  16:20:32  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
Any ideas
Go to Top of Page

Steve D.
Average Member

USA
640 Posts

Posted - 01 April 2003 :  16:26:40  Show Profile  Visit Steve D.'s Homepage  Send Steve D. a Yahoo! Message
wouldn't you want to put it in a table and list it out as follows

Country A | # of members from Country A
Country B | # of members from Country B
Country C | # of members from Country C
Country D | # of members from Country D
Country E | # of members from Country E
etc...

If so just loop through the recordset and output M.M_COUNTRY in one cell and M_COUNT in the next...

Swing Dancing Video Clips - It's All Swing! Forum
Go to Top of Page

mortioli
Average Member

United Kingdom
898 Posts

Posted - 02 April 2003 :  11:51:51  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
Nah, I want to pick out the countries I want, and put them in different places
Go to Top of Page

mortioli
Average Member

United Kingdom
898 Posts

Posted - 07 April 2003 :  11:46:15  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
Any more ideas

EDIT: Please? I really want to try and sort something out which needs this code

Edited by - mortioli on 20 April 2003 12:00:57
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 20 April 2003 :  12:21:24  Show Profile
how about this


function getCountryCount(psCountryName)
	Dim rs, strSql, lTemp

	set rs = server.CreateObject("adodb.recordset")
		strSql = "SELECT COUNT(MEMBER_ID) as CountryCount FROM " & strMemberTablePrefix & "MEMBERS WHERE M_COUNTRY = '" & chkString(psCountryName,"SQLString") & "'"
		rs.Open strSql, my_Conn
		lTemp = rs("CountryCount")
	rs.Close
	set rs = nothing

	getCountryCount = lTemp
end function


Edited by - bjlt on 20 April 2003 12:28:39
Go to Top of Page

Etymon
Advanced Member

United States
2385 Posts

Posted - 21 April 2003 :  11:15:48  Show Profile  Visit Etymon's Homepage
Thank you bjlt for the code! I want to use it for how many guys and gals are in my forum. I am using the Gender MOD.

Cheers,

Etymon
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 22 April 2003 :  12:02:13  Show Profile
Etymon, have you come up with the codes you need? I don't have the gerder mod but here's the code for it.

use it as getGenderCount(1)

function getGenderCount(piGender) '# e.g. 1: male, 2 female ...
	Dim rs, strSql, lTemp

	set rs = server.CreateObject("adodb.recordset")
		strSql = "SELECT COUNT(MEMBER_ID) as GenderCount FROM " & strMemberTablePrefix & "MEMBERS WHERE M_SEX = " & CLng(piGender)
		rs.Open strSql, my_Conn
		lTemp = rs("GenderCount")
	rs.Close
	set rs = nothing

	getGenderCount = lTemp
end function


I don't know the field name for gender used in gender mod you have, change M_SEX to the one it uses if it's not the one.

Also if the gender mod uses male/female etc for sex instead of 1/2, you need to change it to WHERE M_SEX = '" & chkString(piGender,"SQLString") & "'"
then you use it as getGenderCount("male")


Cheers,

Edited by - bjlt on 12 May 2003 23:44:56
Go to Top of Page

mortioli
Average Member

United Kingdom
898 Posts

Posted - 22 April 2003 :  17:12:22  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
quote:
Originally posted by bjlt

how about this


function getCountryCount(psCountryName)
	Dim rs, strSql, lTemp

	set rs = server.CreateObject("adodb.recordset")
		strSql = "SELECT COUNT(MEMBER_ID) as CountryCount FROM " & strMemberTablePrefix & "MEMBERS WHERE M_COUNTRY = '" & chkString(psCountryName,"SQLString") & "'"
		rs.Open strSql, my_Conn
		lTemp = rs("CountryCount")
	rs.Close
	set rs = nothing

	getCountryCount = lTemp
end function





Isn't that the same code as the one in my first post

It means having to change certain parts of it three times for each country (which gets very tedious ), or do I have it wrong!?

Sorry
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 23 April 2003 :  07:20:57  Show Profile
How do you want to use it?
mine has a parameter, use it like this:
getCountryCount("USA")
getCountryCount("Japan")
is it what you want?

Go to Top of Page

mortioli
Average Member

United Kingdom
898 Posts

Posted - 23 April 2003 :  14:52:36  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
But to get the count, for example, for the USA, I'd have to change the parts in red...


function getCountryCount(USA)
	Dim rs, strSql, lTemp

	set rs = server.CreateObject("adodb.recordset")
		strSql = "SELECT COUNT(MEMBER_ID) as USA FROM " & strMemberTablePrefix & "MEMBERS WHERE M_COUNTRY = '" & chkString(USAe,"SQLString") & "'"
		rs.Open strSql, my_Conn
		lTemp = rs("USA")
	rs.Close
	set rs = nothing

	getCountryCount = lTemp
end function


Or do I have that all wrong
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 23 April 2003 :  15:28:59  Show Profile
the diff between yours and mine is that there's a parameter in mine.
no you don't have to change all of them, the code will handle it for you. and that's what a parameter do.

getCountryCount("USA") will get you the count for USA
getCountryCount("Japan") will get you the count for Japan.

How about you just try it and see if it works?

response.write getCountryCount("USA")
or
<%=getCountryCount("Japan")%>


look at the code you can see how a parameter works, and how can a filed name be used.


function getCountryCount(psCountryName)
	Dim rs, strSql, lTemp

	set rs = server.CreateObject("adodb.recordset")
		strSql = "SELECT COUNT(MEMBER_ID) as CountryCount FROM " & strMemberTablePrefix & "MEMBERS WHERE M_COUNTRY = '" & chkString(psCountryName,"SQLString") & "'"
		rs.Open strSql, my_Conn
		lTemp = rs("CountryCount")
	rs.Close
	set rs = nothing

	getCountryCount = lTemp
end function




it dosen't matter if you change CountryCount to whatever no matter what a country you want to count, it's just the filed name you select for the count result, and later we do retrieve the result by getting the value of the field : rs("CountryCount")

Edited by - bjlt on 23 April 2003 15:44:18
Go to Top of Page

mortioli
Average Member

United Kingdom
898 Posts

Posted - 25 April 2003 :  15:34:40  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message


That works great! Thanks!

Wonder if you could help me with something else...

I want to make the text/count of each country to be a link, to open a window, and show what members are from that country (in a list)

Any ideas on the code

Thanks again for your help! I really appreciate it!

Edited by - mortioli on 28 April 2003 16:56:22
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 29 April 2003 :  00:47:21  Show Profile
mortioli, I'm afraid that I'm a bit busy these days. I'll come up with the codes in a day or two but that's not a promise.
Go to Top of Page

mortioli
Average Member

United Kingdom
898 Posts

Posted - 29 April 2003 :  16:14:39  Show Profile  Visit mortioli's Homepage  Send mortioli an AOL message  Send mortioli a Yahoo! Message
No problem

Don't worry if you're busy, I appreciate the help you've already given me
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 08 May 2003 :  14:37:32  Show Profile
mortioli, here's the code. fyi
1. the codes is not (strict) following the snitz practice as I did it for my site first and the original codes had little to do with snitz, the original codes works fine but this one has not been tested. If you want to use snitzlised codes I'm afraid that you have to tweak it yourself.
2. I'm afraid you need to adjust the html part yourself
3. this is a limited version that only shows contact info, which codes you can find in topic.asp, and member name, if you want to show more you can add them yourself.
4. to add more contact info besides email, such as icq, msn, you add the filed name at the end of sql string and follow the related codes in topic.asp and see M_EMAIL in my code as an example.
5. you can ask here for help if you want to add more fields but don't know how.
6. happy snitzing

well, use it this way.

make a link to it as
filename.asp?country=countryname&method=0 or 1 or 2 or 3

0 = all, 1 = male 2 = female 3 = unknown
you may need ChkString("countryname","urlpath") for country name in the link

new codes could be found in the later replies of this topic, old codes here are preserved for reference to see how to add new fields etc.



your header and includes here
<%

'####### Global Variables #######
Dim sCountry, iMethod
Dim iPagesize
Dim iWhichPage, iTotalPages
Dim sSortMethod

sCountry = Trim(Request("country"))
iMethod = Clng(Request("method"))
if iMethod < 0 or iMethod > 3 then iMethod = 0

iPagesize = clng(strPageSize)


'######## Start Content #########

if sCountry = "" then Response.Redirect "MemberCountByCountry.asp" : Response.End '# MemberCountByCountry.asp is a file I use to list num of users for every country. change it to the page you like.

DoListUsersByCountry

'######### End Content ##########
WriteFooter


'####### Procedures Below #######
Sub DoListUsersByCountry
	Dim sSql, rs
	Dim aListByCountry, iRecCount
	Dim i, j
	Dim mMEMBER_ID, mM_NAME, mM_LEVEL, mM_EMAIL, mM_HOMEPAGE, mM_COUNTRY, mM_RECEIVE_EMAIL
	Dim MEMBER_ID, M_NAME, M_LEVEL, M_EMAIL, M_HOMEPAGE, M_COUNTRY, M_RECEIVE_EMAIL
	Dim sClass

	iWhichPage = GetPageNum(Trim(Request("whichpage")))

	'## get user list by country/nationality
	sSQL = "SELECT M.MEMBER_ID, M.M_NAME, M.M_LEVEL, M.M_EMAIL, M.M_HOMEPAGE, M.M_COUNTRY, M.M_RECEIVE_EMAIL FROM " & strMemberTablePrefix & "MEMBERS M WHERE M.M_STATUS = 1 AND M.M_COUNTRY = '" & chkString(sCountry,"SQLString") & "'"

	Select Case iMethod '# I use 0/1/2/3 for sex if you use male/female/etc change it accrodingly below
		Case 1
			sSQL = sSQL & " AND M.M_SEX = 1" '# = 'male'
		Case 2
			sSQL = sSQL & " AND M.M_SEX = 2" '# = 'female'
		Case 3
			sSQL = sSQL & " AND M.M_SEX <> 1 AND M.M_SEX <> 2" '# M.M_SEX <> 'male' AND M.M_SEX <> 'female'
		Case Else
			'
	End Select


	Set rs = Server.CreateObject("ADODB.Recordset")
		rs.cachesize = iPagesize

		rs.open sSQL, my_Conn, adOpenStatic, adLockReadOnly, adCmdText

		if rs.EOF or rs.BOF then  '## No Users found
			iRecCount = 0
		Else
			rs.pagesize = iPagesize
			iTotalPages = cLng(rs.pagecount)
			if iWhichPage > iTotalPages then iWhichPage = iTotalPages
			rs.absolutepage = iWhichPage
			aListByCountry = rs.GetRows(iPagesize)
			iRecCount = UBound(aListByCountry,2) + 1
		End If

	rs.close
	set rs = nothing

	Response.Write	"" &_
		"<table border=0 width=""100%"" cellpadding=""0"" cellspacing=""0"" align=""center"">" & vbNewLine & _
		"	<tr>" & vbNewLine 
	Call DropDownPaging(1)
	Response.Write	"" &_
		"	</tr>" & vbNewLine & _
		"</table>" & vbNewLine &_
		"<table align=""center"" class=""TblList"">" & vbNewLine & _
		"	<tr>" & vbNewLine &_
		"		<th class=""TblHeadCellDefault"">Contact</th>" & vbNewLine & _
		"		<th class=""TblHeadCellDefault"">Member Name</th>" & vbNewLine &_
		"	</tr>" & vbNewLine

	If iRecCount = 0 Then
		Call WriteNoRecCells(2)
	Else
		mMEMBER_ID = 0
		mM_NAME = 1
		mM_LEVEL = 2
		mM_EMAIL = 3
		mM_HOMEPAGE = 4
		mM_COUNTRY = 5
		mM_RECEIVE_EMAIL = 6
		'mM_PMRECEIVE = 7

		i = 0
		j = 0

		For i = 0 to iRecCount - 1
			MEMBER_ID = aListByCountry(mMEMBER_ID,i)
			M_NAME = aListByCountry(mM_NAME,i)
			M_LEVEL = aListByCountry(mM_LEVEL,i)
			M_EMAIL = aListByCountry(mM_EMAIL,i)
			M_HOMEPAGE = aListByCountry(mM_HOMEPAGE,i)
			M_COUNTRY = aListByCountry(mM_COUNTRY,i)
			M_RECEIVE_EMAIL = aListByCountry(mM_RECEIVE_EMAIL,i)
			'M_PMRECEIVE = aListByCountry(mM_PMRECEIVE,i)

			if j = 0 then
				sClass = "TblCellDefault"
			else
				sClass = "TblAltCellDefault"
			end if

			Response.Write	"" &_
			"	<tr>" & vbNewLine & _
			"		<td align=""left"" class=""" & sClass & """>put email, homepage etc codes here</td>" & vbNewLine &_
			"		<td align=""center"" class=""" & sClass & """><a href=""pop_profile.asp?mode=display&id=" & MEMBER_ID & """ target=""profile"">" & ChkString(M_NAME,"display") & "</a></td>" &_
			"	</tr>" & vbNewLine

			j = j + 1
			if j = 2 then j = 0
		Next
	End if

	Response.Write	"" &_
		"</table>" & vbNewLine &_
		"<table border=0 width=""100%"" cellpadding=""0"" cellspacing=""0"">" & vbNewLine & _
		"	<tr>" & vbNewLine
	Call DropDownPaging(2)
	Response.Write	"" &_
		"	</tr>" & vbNewLine & _
		"</table>" & vbNewLine

End Sub


sub DropDownPaging(piNum)
	Dim sAlign, i
	if piNum mod 2 = 0 then
		sAlign = "left"
	Else
		sAlign = "right"
	End If

	if iTotalPages > 1 then
		Response.Write "" &_
		"<form name=""PageNum" & piNum & """ action=""ListUsersByCountry.asp"">" & vbNewLine &_
		"	<input name=""method"" type=""hidden"" value=""" & iMethod & """>" & vbNewLine &_
		"	<input name=""country"" type=""hidden"" value=""" & sCountry & """>" & vbNewLine &_
		"		<td align=""" & sAlign & """>" & vbNewLine
		if iWhichPage > 1 then 
				Response.Write "" &_
		"		<a href=""ListUsersByCountry.asp?country=" & ChkString(sCountry,"urlpath") & "&method=" & iMethod & "&whichpage=" & iWhichPage - 1 & """>Previous Page</a>" & vbNewLine
		end if
		
		Response.Write "<b>Page</b>" & vbNewLine &_
		"		<select name=""whichpage"" size=""1"" onchange=""ChangePage(" & piNum & ");"">" & vbNewLine
		for i = 1 to iTotalPages
			Response.Write "" &_
		"			<option value=""" & i & """"
		if i = iWhichPage then response.write "selected"
		response.write "" &_
		">" & i & "</option>" & vbNewLine
		next
		Response.Write "" &_
		"		</select>" & vbNewLine &_
		"		<b>Total: " & iTotalPages & "</b>? & vbNewLine
		if iWhichPage < iTotalPages then 			
			Response.Write "" &_
		"		<a href=""ListUsersByCountry.asp?country=" & ChkString(sCountry,"urlpath") & "&method=" & iMethod & "&whichpage=" & iWhichPage + 1 & """>Next Page</a>" & vbNewLine
		end if
		Response.Write "" &_
		"		</td>" & vbNewLine &_
		"</form>" & vbNewLine
	else
		Response.Write "<td>?lt;/td>"
	end if
end sub 

Sub WriteNoRecCells(colspan)
	Response.Write	"" &_
		"	<tr>" & vbNewLine & _
		"		<td class=""TblCellDefault"" colspan=""" & colspan & """ align=""center""> No Members </td>" & vbNewLine &_
		"	</tr>" & vbNewLine
End Sub

Function GetPageNum(piPage)
	if piPage = "" or not isnumeric(piPage) then
		GetPageNum = 1
	else
		GetPageNum = Clng(piPage)
		if GetPageNum < 1 then GetPageNum = 1
	end if
End Function
%>


edit minor bug fix in blue

Edited by - bjlt on 11 May 2003 07:49:39
Go to Top of Page
Page: of 4 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.27 seconds. Powered By: Snitz Forums 2000 Version 3.4.07