12-08-2004, 07:47 PM
[syntax="php"]<?
/* Connect to the dataabase...what else? */
mysql_connect(localhost, '****', '****');
mysql_select_db('****');
/* Get the row data */
$query="SELECT * FROM `qbntc_rq` ORDER BY `id` ASC";
$result=mysql_query($query);
$num=mysql_num_rows($result);
/* begin sorting the jbberish */
$offset=0;
$query="SELECT * FROM qbntc_vote";
$r=mysql_query($query);
$n=mysql_num_rows($r);
/* Almost a bubble sort, but im i=not comparing data..this stuff was only in my mind for a few seconds before it 'disappeared', so im not sure how well I can explain it */
for ($s=0;$s<$n;$s++)
{
// Make sure we only record one 'quote' per loop
$vid=mysql_result($r,$s,'vote_id');
$v=mysql_result($r,$s,'vote');
if ($v==1)
{
$sort[$vid] [($s-$offset)]++;
$yes[$vid]++;
$a++;
} else {
$sort[$vid] [($s-$offset)]--;
$no[$vid]++;
$a++;
}
}
mysql_close();
print("<TABLE width='100%' cellpadding=0 cellspacing=1 border=0> \n");
print("<TR><TD width='15%' bgcolor='black'><font color='white'>Rank</font></TD><TD bgcolor='Black'><font color='white'>Quote:</font></TD></TR> \n");
if ($num >= 1) {
for ($i=0;$i<$num;$i++)
{
if ($i%2==0) {
$colour="#4372FB";
} else {
$colour="#0080C0";
}
$sub=mysql_result($result,$i,'user');
$quotee=mysql_result($result,$i,'quoteduser');
$quote=mysql_result($result,$i,'quote');
$ds=mysql_result($result,$i,'date');
$rank=$sort[$i] [1]; // I'm not sure what to replace '1' with...
print("<TR bgcolor='$colour'><TD valign='middle' align='center'>" . $rank . "</TD><TD>" . $quote ."</TD></TR> \n");
print("<TR bgcolor='$colour'><TD colspan=2><font size=1>Submitted By <font color='yellow' size=>$sub</font> | Submitted on <font color='yellow' size=>$ds</font> | Poll Results: Yes [<font color='yellow'>$yes[$i]</font>] No [<font color='yellow'>$no[$i]</font>]</font></TD></TR> \n");
}
} else {
print("<TR><TD colspan=2 align='center'><i>Unable to determine rank :: No quotes submitted</i></TD></TR> \n");
}
print("</TABLE> \n");
?>[/syntax]
There is lots wrong with it.....I'll try to comment it to say where things are going wrong, and whats happening.
Oz~
/* Connect to the dataabase...what else? */
mysql_connect(localhost, '****', '****');
mysql_select_db('****');
/* Get the row data */
$query="SELECT * FROM `qbntc_rq` ORDER BY `id` ASC";
$result=mysql_query($query);
$num=mysql_num_rows($result);
/* begin sorting the jbberish */
$offset=0;
$query="SELECT * FROM qbntc_vote";
$r=mysql_query($query);
$n=mysql_num_rows($r);
/* Almost a bubble sort, but im i=not comparing data..this stuff was only in my mind for a few seconds before it 'disappeared', so im not sure how well I can explain it */
for ($s=0;$s<$n;$s++)
{
// Make sure we only record one 'quote' per loop
$vid=mysql_result($r,$s,'vote_id');
$v=mysql_result($r,$s,'vote');
if ($v==1)
{
$sort[$vid] [($s-$offset)]++;
$yes[$vid]++;
$a++;
} else {
$sort[$vid] [($s-$offset)]--;
$no[$vid]++;
$a++;
}
}
mysql_close();
print("<TABLE width='100%' cellpadding=0 cellspacing=1 border=0> \n");
print("<TR><TD width='15%' bgcolor='black'><font color='white'>Rank</font></TD><TD bgcolor='Black'><font color='white'>Quote:</font></TD></TR> \n");
if ($num >= 1) {
for ($i=0;$i<$num;$i++)
{
if ($i%2==0) {
$colour="#4372FB";
} else {
$colour="#0080C0";
}
$sub=mysql_result($result,$i,'user');
$quotee=mysql_result($result,$i,'quoteduser');
$quote=mysql_result($result,$i,'quote');
$ds=mysql_result($result,$i,'date');
$rank=$sort[$i] [1]; // I'm not sure what to replace '1' with...
print("<TR bgcolor='$colour'><TD valign='middle' align='center'>" . $rank . "</TD><TD>" . $quote ."</TD></TR> \n");
print("<TR bgcolor='$colour'><TD colspan=2><font size=1>Submitted By <font color='yellow' size=>$sub</font> | Submitted on <font color='yellow' size=>$ds</font> | Poll Results: Yes [<font color='yellow'>$yes[$i]</font>] No [<font color='yellow'>$no[$i]</font>]</font></TD></TR> \n");
}
} else {
print("<TR><TD colspan=2 align='center'><i>Unable to determine rank :: No quotes submitted</i></TD></TR> \n");
}
print("</TABLE> \n");
?>[/syntax]
There is lots wrong with it.....I'll try to comment it to say where things are going wrong, and whats happening.
Oz~