How to calculate the percentage of progress bar displayed at the end of voting

PHP中文网
Release: 2023-02-28 18:40:01
Original
2636 people have browsed it

A voting result I wrote myself shows that the progress bar with the most votes is set to 100%.

public class voteresult : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlTableCell td_vote;
protected System.Web.UI.HtmlControls.HtmlTable tab_result;
private void Page_Load(object sender, System.EventArgs e)// 在此处放置用户代码以初始化页面
{
tab_result=new HtmlTable();
string voteid=Request.Params["voteid"];
string optionid=Request.Params["optionid"];
CommonFunction.SQLConnection scon=new SQLConnection();
System.Data.DataTable dt;
System.Web.UI.HtmlControls.HtmlTableCell tc;
System.Web.UI.HtmlControls.HtmlTableRow tr;
string sql="";
sql="update voteinfo set optioncount=optioncount+1 where voteid="+voteid+" and optionid="+optionid;
scon.OperationRecord(sql);
sql="select optionstr,optioncount from voteinfo where voteid="+voteid;dt=scon.Query(sql);
int i=0;
int length=0;
while(i<dt.Rows.Count)
{
if(length<(int)dt.Rows[i].ItemArray[1])
length=(int)dt.Rows[i].ItemArray[1];
i++;
}
i=0;
td_vote.InnerHtml="<table border=\"1\" cellspacing=\"1\" cellpadding=\"1\" align=\"center\">";
while(i<dt.Rows.Count)
{
td_vote.InnerHtml+="<tr>";
td_vote.InnerHtml+="<td>";
td_vote.InnerHtml+=(string)dt.Rows[i].ItemArray[0];
td_vote.InnerHtml+="</td><td width=\"200\">";
//tc=new HtmlTableCell();
//tr=new HtmlTableRow();
//tc.InnerText=
//tr.Cells.Add(tc);
//tc=new HtmlTableCell();
td_vote.InnerHtml+="<img src=\"images/long.gif\" width=\""+(((int)dt.Rows[i].ItemArray[1]*100/length)*2)+"\" height=\"9\">";
//tc.InnerHtml=
//tr.Cells.Add(tc);
td_vote.InnerHtml+="</td><td>";
td_vote.InnerHtml+=((int)dt.Rows[i].ItemArray[1]).ToString();;
//tc=new HtmlTableCell();
//tc.InnerText=
td_vote.InnerHtml+="</td></tr>";
i++;
}
td_vote.InnerHtml+="</table>";
}
Copy after login

Related articles:

How to ensure that the sum of each part is 1 when calculating percentages in PHP

php sector ratio percentage display program Code

PHP execution progress percentage code

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template