|
|
|
โค้ดรันใน localhost ได้ปกติ แต่พออัพขึ้นโฮสกลับใช้ไม่ได้ ไม่แสดงผล ช่วยแก้ทีค่ะ |
|
|
|
|
|
|
|
Code (PHP)
<?php
if ( $Flag == 0 )
$msg = "ท่านต้องรออีก 1 ชั่วโมง ถึงจะโหวตใหม่ได้อีกครั้งหนึ่ง";
else
$msg = "";
?>
<html>
<head>
<title>View Poll</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="poll.css" type="text/css">
</head>
<body bgcolor="#F1F1F1" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<p align="center" class="Tahoma13"><?php echo $msg; ?></p>
<table width="50%" border="0" cellspacing="0" cellpadding="1" align="center">
<tr>
<td bgcolor="#FFCC00">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td align="center" class="Tahoma13"><b>:: EOL Poll สรุปผลคะแนน ::</b></td>
</tr>
<tr>
<td bgcolor="#F1F1F1" valign="top" class="Tahoma13">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<?php
include( "phpConfig.php" );
include( "phpFunctionDB.php" );
Conn2DB();
$PollTotal = SumPollVote( $sID );
$strSQL = "SELECT * ";
$strSQL .= "FROM tbl_subject AS s, tbl_item AS i ";
$strSQL .= "WHERE s.sID=i.sID ";
$strSQL .= "AND s.sID='$sID' ";
$res = mysql_query( $strSQL );
while ( $rs = mysql_fetch_array( $res ) )
{
$iVote = $rs[iVote];
if ( $PollTotal == 0 )
$CalPercent = 0;
else
$CalPercent = ( $rs[iVote] / $PollTotal ) * 100;
echo "<tr valign=\"top\">\n";
echo "<td width=\"33%\" class=\"Tahoma13\">$rs[iTitle]</td>\n";
echo "<td width=\"55%\" class=\"Tahoma13\">";
echo "<img src=\"img/green.gif\" width=\"$CalPercent\" height=\"10\"> ";
echo "($iVote)";
echo "</td>\n";
echo "<td width=\"12%\" align=\"right\" class=\"Tahoma13\">";
echo number_format( $CalPercent, 2, '.', ',' );
echo "%</td>\n";
echo "</tr>\n";
}
CloseDB();
?>
</table>
</td>
</tr>
<tr>
<td align="center" class="Tahoma13">[รวมทั้งหมด <b><?php echo $PollTotal; ?> </b>ท่าน]</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
</body>
</html>
Code (PHP)
<?php
include( "phpConfig.php" );
include( "phpFunctionDB.php" );
Conn2DB();
$strSQL = "SELECT sID FROM tbl_subject";
$res = mysql_query( $strSQL );
while ( $rs = mysql_fetch_array( $res ) )
{
$sIDarr[] = $rs[sID];
}
srand( ( double ) microtime()*1000000 );
$sID = rand( 0, count( $sIDarr ) );
if ( $sID != 0 )
$sID = $sID-1;
?>
<html>
<head>
<title>Poll</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="poll.css" type="text/css">
</head>
<body bgcolor="#F1F1F1" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<br>
<table width="200" border="0" cellspacing="0" cellpadding="1" align="center">
<form name="FrmPoll" method="post" action="phpPoll.php">
<input type="hidden" name="sID" value="<?php echo $sIDarr[$sID]; ?>">
<tr>
<td bgcolor="#FFCC00">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td align="center" class="Tahoma13"><b>:: EOL Poll ::</b></td>
</tr>
<tr>
<?php
$strSQL1 = "SELECT * ";
$strSQL1 .= "FROM tbl_subject AS s, tbl_item AS i ";
$strSQL1 .= "WHERE s.sID=i.sID ";
$strSQL1 .= "AND s.sID=$sIDarr[$sID]";
$res1 = mysql_query( $strSQL1 );
$PollTitle = GetPollTitle( $sIDarr[$sID] );
echo "<td bgcolor=\"#F1F1F1\" valign=\"top\" class=\"Tahoma13\">$PollTitle<br>\n";
while ( $rs1 = mysql_fetch_array( $res1 ) )
{
echo "<input type=\"radio\" name=\"iID\" value=\"$rs1[iID]\">$rs1[iTitle]<br>\n";
}
CloseDB();
?>
<center><input type="submit" name="Submit" value=" Vote "></center>
</td>
</tr>
<tr>
<td align="center" class="Tahoma13">[<a href="phpViewPoll.php?sID=<?php echo $sIDarr[$sID]; ?>&Flag=1">สรุปผลคะแนน</a>]</td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<br>
</body>
</html>
Code (PHP)
<?php
$conn;
function Conn2DB()
{
global $conn;
global $ServerName;
global $UserName;
global $UserPassword;
global $DataBaseName;
$conn = mysql_connect( $ServerName, $UserName, $UserPassword )
or die( "äÁèÊÒÁÒöµÔ´µè͡Ѻ MySQL ä´é" );
mysql_query( "SET NAMES utf8", $conn );
mysql_select_db( $DataBaseName, $conn )
or die ( "äÁèÊÒÁÒöàÅ×Í¡ãªé§Ò¹°Ò¹¢éÍÁÙÅ $DataBaseName ä´é" );
}
function CloseDB()
{
global $conn;
mysql_close( $conn );
}
function GetPollTitle( $sID )
{
global $conn;
$strSQL = "SELECT sTitle FROM tbl_subject WHERE sID='$sID' ";
$result = mysql_query( $strSQL, $conn )
or die ( "SELECT GetPollTitle มีข้อผิดพลาด" . mysql_error() );
$rs = mysql_fetch_array( $result );
return $rs[sTitle];
}
function UpdatePollVote( $iID )
{
global $conn;
$strSQL = "UPDATE tbl_item SET iVote=iVote+1 WHERE iID='$iID' ";
mysql_query( $strSQL, $conn )
or die ( "UPDATE มีข้อผิดพลาดเกิดขึ้น" ) . mysql_error();
}
function SumPollVote( $sID )
{
global $conn;
$strSQL = "SELECT SUM(iVote) AS Total FROM tbl_item WHERE sID='$sID' ";
$result = mysql_query( $strSQL, $conn )
or die ( "SELECT SumPollVote มีข้อผิดพลาด" . mysql_error() );
$rs = mysql_fetch_array( $result );
return $rs["Total"];
}
function Insert2Log( $iID, $gIP )
{
global $conn;
$gDateLog = date( "Y-m-d H:i:s" );
$strSQL = "INSERT INTO tbl_log ( iID, gIP, gDateLog ) VALUES ( $iID, '$gIP', '$gDateLog' )";
mysql_query( $strSQL, $conn )
or die ( "INSERT มีข้อผิดพลาด" ) . mysql_error();
}
?>
Code (PHP)
<?php
include( "phpConfig.php" );
include( "phpFunctionDB.php" );
Conn2DB();
if ( ! isset( $Session["sID"][$sID] ) )
{
$gIP = $REMOTE_ADDR;
UpdatePollVote( $iID );
Insert2Log( $iID, $gIP );
setcookie ( "Session[sID][$sID]", $sID, time()+3600 );
header( "Location: phpViewPoll.php?sID=$sID&Flag=1" );
}
else
{
header( "Location: phpViewPoll.php?sID=$sID&Flag=0" );
}
CloseDB();
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2012-02-07 10:08:31 |
By :
fasaiaya |
View :
1064 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
POST ค่ะ แล้วต้องเขียนยังไงตรงไหนค่ะ มือใหม่มากๆเลย -*-
|
|
|
|
|
Date :
2012-02-08 09:29:55 |
By :
fasaiaya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้แล้ว ขอบคุณค่ะพี่
|
|
|
|
|
Date :
2012-02-08 09:49:23 |
By :
fasaiaya |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|