Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
really messy php for qbn_tc
#1
[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>&nbsp;|&nbsp;Submitted on <font color='yellow' size=>$ds</font>&nbsp;|&nbsp;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~
Reply
#2
After searching for a while, I fixed it all up

nvm

Oz~
Reply
#3
Now I have a seperate thing that has kinda bugged up after I switched the order around...

[syntax="php"]<HTML>
<HEAD>
<title>Updating...</title>
<meta http-equiv="refresh" content="3;url=http://www.atosoftqb.digitalblackie.com/qbn_tc/">
</HEAD>
</HTML>

<?

$voteid=$_GET['vid'];
$answer=$_GET['select'];

$ip=getenv("REMOTE_ADDR");

if (($answer<-1) || ($answer>1) || ($answer==0))
{
echo "Trying to tamper with the system, eh?\n";
exit;
}

if ($answer==1)
{
$send="yes";
} else {
$send="no";
}

mysql_connect(localhost, '****', '****');
mysql_select_db('****');

$query="SELECT * FROM qbntc_voted";
$result=mysql_query($query);
$num=mysql_num_rows($result);

for ($i=0;$i<$num;$i++)
{
$tip=mysql_result($result,$i,'ip');
$voted=mysql_result($result,$i,'vote_id');
if ( strcmp ( $ip, $tip ) == 0 )
{
if ($voted==$voteid)
{
echo "You have already voted on this quote!";
exit;
}
}
}
//If you are able to proceed past this, then you have not cast a vote on the poll
//First record your ip to manage the polling

$query="INSERT INTO `qbntc_voted` (`id`, `ip`, `vote_id`, `vote`) VALUES ('', '$ip', '$voteid', '$answer');";
$result=mysql_query($query);

if ($result==FALSE)
{
print "An error occured while recording IP address\r\n<br>" . mysql_error();
}

$query="SELECT * FROM qbntc_rq";
$result=mysql_query($query);
$num=mysql_num_rows($result);

mysql_close();

if ($result==FALSE)
{
echo mysql_error();
}


print "\nVoting <i>$send</i> from <b>$ip</b> on Quote ID <b>$voteid</b>\n";

?>[/syntax]

Oz~
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)