Jump to content

Poll


zuper89

Recommended Posts

How can i make this much more simpler?

<%DIM objConnSet objConn = Server.CreateObject("ADODB.Connection")objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db/timerussen.mdb") & ";"objConn.OpenmySQL = "SELECT * FROM poll"DIM objPOSet objPO = Server.CreateObject("ADODB.Recordset")objPO.Open mySQL, objConn%><html><head></head><body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"><table cellpadding="0" cellspacing="0" border="0" width="400"><%DIM sumsum = (objPO("po_votes1") + objPO("po_votes2") + objPO("po_votes3") + objPO("po_votes4") + objPO("po_votes5") + objPO("po_votes6") + objPO("po_votes7") + objPO("po_votes8") )%>  <tr>    <td align="center"><b><% Response.Write objPO("po_sporsmal") %></b><br>Totalt votes: <% Response.Write(sum) %></td>  </tr></table><%If objPO("po_svar1") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar1") %></td>  </tr>  <tr>  <%  DIM votes1a, votes1b, votes1c  votes1a = (objPO("po_votes1") / sum * 100)  votes1b = (100 - votes1a)  votes1c = Round(votes1a, 2)  %>    <td background="includes/images/1.gif" height="18" width="<% Response.Write(votes1a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes1b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes1") %> (<% Response.Write(votes1c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar2") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar2") %></td>  </tr>  <tr>  <%  DIM votes2a, votes2b, votes2c  votes2a = (objPO("po_votes2") / sum * 100)  votes2b = (100 - votes2a)  votes2c = Round(votes2a, 2)  %> 	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes2a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes2b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes2") %> (<% Response.Write(votes2c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar3") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar3") %></td>  </tr>  <tr>  <%  DIM votes3a, votes3b, votes3c  votes3a = (objPO("po_votes3") / sum * 100)  votes3b = (100 - votes3a)  votes3c = Round(votes3a, 2)  %> 	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes3a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes3b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes3") %> (<% Response.Write(votes3c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar4") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar4") %></td>  </tr>  <tr>  <%  DIM votes4a, votes4b, votes4c  votes4a = (objPO("po_votes4") / sum * 100)  votes4b = (100 - votes4a)  votes4c = Round(votes4a, 2)  %> 	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes4a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes4b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes4") %> (<% Response.Write(votes4c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar5") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar5") %></td>  </tr>  <tr>  <%  DIM votes5a, votes5b, votes5c  votes5a = (objPO("po_votes5") / sum * 100)  votes5b = (100 - votes5a)  votes5c = Round(votes5a, 2)  %> 	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes5a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes5b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes5") %> (<% Response.Write(votes5c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar6") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar6") %></td>  </tr>  <tr>  <%  DIM votes6a, votes6b, votes6c  votes6a = (objPO("po_votes6") / sum * 100)  votes6b = (100 - votes6a)  votes6c = Round(votes6a, 2)  %> 	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes6a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes6b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes6") %> (<% Response.Write(votes6c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar7") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar7") %></td>  </tr>  <tr>  <%  DIM votes7a, votes7b, votes7c  votes7a = (objPO("po_votes7") / sum * 100)  votes7b = (100 - votes7a)  votes7c = Round(votes7a, 2)  %> 	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes7a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes7b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes7") %> (<% Response.Write(votes7c) %>%)</i></td>  </tr></table><%End IfIf objPO("po_svar8") <> "" Then%><table cellpadding="0" cellspacing="0" border="0" width="400">  <tr>    <td colspan="2"><% Response.Write objPO("po_svar8") %></td>  </tr>  <tr>  <%  DIM votes8a, votes8b, votes8c  votes8a = (objPO("po_votes8") / sum * 100)  votes8b = (100 - votes8a)  votes8c = Round(votes8a, 2)  %>  	<td background="includes/images/1.gif" height="18" width="<% Response.Write(votes8a) %>%"></td>	<td background="includes/images/0.gif" height="18" width="<% Response.Write(votes8b) %>%"></td>  </tr>  <tr>    <td colspan="2"><i>Votes: <% Response.Write objPO("po_votes8") %> (<% Response.Write(votes8c) %>%)</i></td>  </tr></table><%End If%></body></html><%objPO.CloseSet objPO = NothingobjConn.CloseSet objConn = Nothing%>

Link to comment
Share on other sites

Maybe its just me, but I put my connection string in an 'include'; that way if the connection ever needs to be changed, I can do it in one place instead of fifty.... now I bet that would get repetitive. :)

why use includes??? Includes make reusing repetitive code easy....none of the provided code makes sense to break into includes.  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...