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/Code)
 Poll Mod v2.0.8
 New Topic  Reply to Topic
 Printer Friendly
Previous Page | Next Page
Author Previous Topic Topic Next Topic
Page: of 3

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 29 April 2009 :  15:50:20  Show Profile  Reply with Quote
I don't remember multiple choices being 1 of the options. It was something on my to-do list tho. I'll be having some time on my hands, so I might just work something in when I update the poll mod.

The poll mod takes up so many database fields. Sometimes I wonder if there isn't a more efficient way of storing poll data.

Support Snitz Forums
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 29 April 2009 :  16:14:19  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
There is, David. It would be a different thing altogether. If you are considering that possibility, I can think about that design.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 29 April 2009 :  16:39:17  Show Profile  Reply with Quote
Yeah I am Rui. Run the design by me, if you would. Basically looking to use less database fields, altho not at the cost of performance issues.

Persons are looking for more poll options but creating countless database fields to hold them seems ridiculous. lol

Support Snitz Forums
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 29 April 2009 :  17:34:34  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
Hi David,

I guess if you want a new DB structure, probably migration from the current one should be the most direct possible. This proposed structure represents a compromise, because it would just solve the problem of wasting dabatase space and allowing more than 15 options.

Basically I suggest that you split the POLLS table into two:

POLLS:

POLL_ID,
CAT_ID,
FORUM_ID,
TOPIC_ID,
P_WHOVOTES,
P_LASTVOTE

POLL_ANSWER:
ANSWER_ID
POLL_ID,
ANSWER_TEXT,
ORDER, <- Order of the answer in the poll
COUNT

Then use the POLL_VOTES as you have it now.

This is pretty close to what you have now. It would also mean that migrating from the existing structure to the current one should be really simple.

I can provide further detail, if needed.

This is not the best possible structure, but a reasonable compromise, as I said, considering that there are quite a few installs and changing your code to use this shouldn't be too hard.

Let me know what you think.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Etymon
Advanced Member

United States
2385 Posts

Posted - 30 April 2009 :  01:42:10  Show Profile  Visit Etymon's Homepage  Reply with Quote
This is fun! Thanks guys!
Go to Top of Page

Carefree
Advanced Member

Philippines
4207 Posts

Posted - 30 April 2009 :  02:20:19  Show Profile  Reply with Quote
Multiple choices are possible now, if options such as ("Both A and C") are used; though when possible single choices exceed four, that can quickly become unwieldy (a, b, c, d, a&b, a&c, a&d, b&c, b&d, c&d, a&b&c, a&b&d, b&c&d, a&c&d, a&b&c&d). It would be much simpler to use checkboxes vs radio buttons and thus allow multiple choices.
Go to Top of Page

SiSL
Average Member

Turkey
671 Posts

Posted - 30 April 2009 :  04:24:56  Show Profile  Visit SiSL's Homepage  Reply with Quote
quote:
This is not the best possible structure


Actually Rui, you are wrong. Your method IS the best possible structure. (May be can loose auto increment ANSWER_ID there, since there is ORDER and POLL_ID required) Actually I decided to give it a try right now. However, migration might be the toughest part.


CHIP Online Forum

My Mods
Select All Code | Fix a vulnerability for your private messages | Avatar Categories W/ Avatar Gallery Mod | Complaint Manager
Admin Level Revisited | Merge Forums | No More Nested Quotes Mod

Edited by - SiSL on 30 April 2009 04:39:57
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 30 April 2009 :  09:33:56  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
Yeah, guess you can have order and poll_id as the primary key for the POLL_ANSWER table. The poll mod code will have to be redone for this, of course. "Hardest" thing will be the form to create a poll, since the number of answers will now be variable. Probably using a list instead of fixed text fields would be a better option.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

SiSL
Average Member

Turkey
671 Posts

Posted - 30 April 2009 :  09:52:56  Show Profile  Visit SiSL's Homepage  Reply with Quote
quote:
Originally posted by ruirib

Yeah, guess you can have order and poll_id as the primary key for the POLL_ANSWER table. The poll mod code will have to be redone for this, of course. "Hardest" thing will be the form to create a poll, since the number of answers will now be variable. Probably using a list instead of fixed text fields would be a better option.



I still limit it to 15, like + and - signs... (I dont find it reasonable or logical to allow unlimited number of polls) So on For Next, if it sees an empty answer, exits for... And limits the poll like that.

However, database will be a lot lighter...
IMO, hardest (well, not hardest, but still need work) part would be "updating" records...

So I went a way to Take all counts of Poll -> Delete answers entirely -> Insert again mode (for empty responses or old stuff not to remain there) and not sure if there is faster way to do that...

I think it works fine on my test server now, also updated pop_delete for that as well (but for Category or Forum deletions, I need to work on it more, but heck, I dont delete cats or forums that much eheh) Most likely I can not make it into a mod, since my poll mod is also modded a lot, but principles remains same.

CHIP Online Forum

My Mods
Select All Code | Fix a vulnerability for your private messages | Avatar Categories W/ Avatar Gallery Mod | Complaint Manager
Admin Level Revisited | Merge Forums | No More Nested Quotes Mod

Edited by - SiSL on 30 April 2009 09:59:03
Go to Top of Page

modifichicci
Average Member

Italy
787 Posts

Posted - 30 April 2009 :  10:44:02  Show Profile  Visit modifichicci's Homepage  Reply with Quote
Don't forget the archive function as well...

Ernia e Laparocele
Forum di Ernia e Laparocele
Acces - MySql Migration Tutorial
Adamantine forum
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 30 April 2009 :  10:59:25  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
Watch out the indexing, if you have a few polls...


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 30 April 2009 :  11:04:59  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
I could have written a nice little SQL Server script for migration, if you had told me so. Not hard, using cursors. Can't say the same for Access and MySQL, cause it would needed to be done using asp.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

SiSL
Average Member

Turkey
671 Posts

Posted - 30 April 2009 :  12:40:08  Show Profile  Visit SiSL's Homepage  Reply with Quote
quote:
Originally posted by modifichicci

Don't forget the archive function as well...



I dont think Archieve would have anything to do with other tables, since Poll ID is unique and equals to Topic Id.

CHIP Online Forum

My Mods
Select All Code | Fix a vulnerability for your private messages | Avatar Categories W/ Avatar Gallery Mod | Complaint Manager
Admin Level Revisited | Merge Forums | No More Nested Quotes Mod
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 30 April 2009 :  12:45:20  Show Profile  Send ruirib a Yahoo! Message  Reply with Quote
Indeed, archiving just means archiving the topic.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

SiSL
Average Member

Turkey
671 Posts

Posted - 30 April 2009 :  13:49:41  Show Profile  Visit SiSL's Homepage  Reply with Quote
Ok, here goes

topic.asp, I changed as following:

DB as following DB Name: strTablePrefix & "POLL_ANSWERS"


POLL_ID (int, not null)
ANSWER_TEXT (nvarchar(255), null)
ANSWER_ORDER (int, not null)
COUNT (default value=0, int, not null)

This is SQL Server version, using GetRows, would be nice if someone know how to apply it to Access and such.




	'############## Poll Mod ##################
	IsPoll = rsTopic("T_ISPOLL")
	Forum_Polls = rsTopic("F_POLLS")
	Poll_Status = rsTopic("T_POLLSTATUS")
	
	if IsPoll = 1 then
		
		strSql = "SELECT P.P_LASTVOTE, P.P_WHOVOTES"
		' Also removed commas , careful on that
                'For i = 1 To 15
		'	strSql = strSql & ", P.ANSWER" & CStr(i)
		'	strSql = strSql & ", P.COUNT" & CStr(i)
		'Next
		strSql = strSql & " FROM " & strTablePrefix & "POLLS P"
		strSql = strSql & " WHERE P.TOPIC_ID = " & Topic_ID

		set rsPoll = Server.CreateObject("ADODB.Recordset")
		rsPoll.Open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
		
		if not(rsPoll.EOF) or not(rsPoll.BOF) then
			Last_Vote = rsPoll("P_LASTVOTE")
			strWhoVotes = rsPoll("P_WHOVOTES")
			rsPoll.Close
			set rsPoll = nothing
			
			strSQL = "SELECT ANSWER_TEXT, ANSWER_COUNT FROM " & strTablePrefix & "POLL_ANSWERS WHERE POLL_ID=" & Topic_ID
			set rsPoll = Server.CreateObject("ADODB.Recordset")
			rsPoll.Open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
			if not rsPoll.EOF or rsPoll.BOF Then
				tumPoll = rsPoll.GetRows
				For i=0 to UBound(tumPoll,2)
					z = i+1
					vAnswers(z) = tumPoll(0,i)
					vCount(z) = tumPoll(1,i)
					
				Next
			End If
		
		end if
		
		rsPoll.Close
		set rsPoll = nothing
		end if
		if IsPoll = 1 then
			pollLink = "poll=1&"
			
		else
			pollLink = ""
		end if
	'##########################################



Also in another Poll mod marked places inside I changed a few lines starting with if to end...

if nNumber <> -1 then
				'## Forum_SQL - 
				strSql = "UPDATE " & strTablePrefix & "POLLS "
				strSql = strSql & " SET  P_LASTVOTE = '" & DateToStr(strForumTimeAdjust) & "'"
				strSql = strSql & " WHERE TOPIC_ID = " & Topic_ID
			
				my_Conn.Execute (strSql),,adCmdText + adExecuteNoRecords
				
				strSql = "UPDATE " & strTablePrefix & "POLL_ANSWERS "
				strSql = strSql & "  SET ANSWER_COUNT = ANSWER_COUNT+1"
				strSql = strSql & " WHERE POLL_ID = " & Topic_ID & " AND ANSWER_ORDER = " & nNumber
			
				my_Conn.Execute (strSql),,adCmdText + adExecuteNoRecords
				
				Voted = true
				
				'## Forum_SQL -
				strSql = "SELECT " & strTablePrefix & "POLLS.P_LASTVOTE"
				'For i = 1 To 15
				'	strSql = strSql & ", " & strTablePrefix & "POLLS.ANSWER" & CStr(i) 
				'	strSql = strSql & ", " & strTablePrefix & "POLLS.COUNT" & CStr(i)
				'Next
				strSql = strSql & " FROM " & strTablePrefix & "POLLS"
				strSql = strSql & " WHERE " & strTablePrefix & "POLLS.TOPIC_ID = " & Topic_ID
				
				set rsPoll = Server.CreateObject("ADODB.Recordset")
				rsPoll.open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
				
				Last_Vote = rsPoll("P_LASTVOTE")
				rsPoll.Close
				set rsPoll = nothing
				strSQL = "SELECT ANSWER_TEXT, ANSWER_COUNT FROM " & strTablePrefix & "POLL_ANSWERS WHERE POLL_ID=" & Topic_ID
				set rsPoll = Server.CreateObject("ADODB.Recordset")
				rsPoll.Open strSql, my_Conn, adOpenForwardOnly, adLockReadOnly, adCmdText
				if not rsPoll.EOF or rsPoll.BOF Then
				tumPoll = rsPoll.GetRows
				For i=0 to UBound(tumPoll,2)
					z = i+1
					vAnswers(z) = tumPoll(0,i)
					vCount(z) = tumPoll(1,i)
					
				Next
			End If
				
				rsPoll.Close
				set rsPoll = nothing
			
				Call UpdateVote("0", MemberID, Topic_ID, Forum_ID, Cat_ID)
			end if

CHIP Online Forum

My Mods
Select All Code | Fix a vulnerability for your private messages | Avatar Categories W/ Avatar Gallery Mod | Complaint Manager
Admin Level Revisited | Merge Forums | No More Nested Quotes Mod

Edited by - SiSL on 30 April 2009 14:16:47
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Previous Page | Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000 Version 3.4.07