|
|
|
ช่วยผมทีครับ ทำยังไงข้อมูลถึงจะออกแบบนี้ครับ เพราะเพิ่มตารางเข้าไปใหม่เลยทำให้มันเป็นออย่างที่เห็นครับ |
|
|
|
|
|
|
|
ต้องการให้ออกแบบนี้ครับ
ตอนนี้มัน eror แบบนี้ครับ
Code (PHP)
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\full\inc\functions.php on line 15
ฐานข้อมูลมี 3 ตารางครับ tblpdorm tblpollanswers และ tblpolls ตามลำดับครับ
โค้ดหน้ารับข้อมูล
Code (PHP)
<?
require("inc/functions.php");
$query58 = "SELECT * FROM tblpolls WHERE dorm_id = '".$_GET['id']."' ORDER By pollID ASC";
$result8 = mysql_query($query58);
$row5 = mysql_fetch_array($result8);
{
$su = $row5['pollID'];
$strSQLw = "SELECT * FROM tblpdorm where pollID = '".$su."' and member_user = '".$_SESSION['login_true_google']."'order by pdorm_id+1 desc";
$objQueryw = mysql_query($strSQLw) or die ("Error Query [".$strSQLw."]");
$numw = mysql_num_rows($objQueryw);
$objResult = mysql_fetch_array($objQuery);
{
if($numw <= 0)
{
//echo $numw;
getPoll($su);
}
echo "<br><br>";
}
}
?>
หน้าฟังชั่นครับ
Code (PHP)
<?php
require("db.php");
//GETTING VARIABLES START
$action = mysql_real_escape_string($_POST['action']);
$pollAnswerID = mysql_real_escape_string($_POST['pollAnswerID']);
$pollID = mysql_real_escape_string($_POST['pollID']);
//GETTING VARIABLES END
session_start() ;
function getPoll($pollID){
$query = "SELECT * FROM tblpolls LEFT JOIN tblpollanswers ON tblpolls.pollID = tblpollanswers.pollID WHERE tblpolls.pollID = " . $pollID . " ORDER By pollAnswerListing ASC";
$result = mysql_query($query);
//echo $query;jquery
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$pollQuestion = $row['pollQuestion'];
$pollAnswerID = $row['pollAnswerID'];
$pollID = $row['pollID'];
$pollAnswerValue = $row['pollAnswerValue'];
if ($pollStartHtml == '') {
$pollStartHtml = '<div id="pollWrap"><form name="pollForm" method="post" action="inc/functions.php?action=vote"><h3>' . $pollQuestion .'</h3><ul>';
$pollEndHtml = '</ul><input type="submit" name="pollSubmit" id="pollSubmit" value="Vote" /> <span id="pollMessage"></span><img src="ajaxLoader.gif" alt="Ajax Loader" id="pollAjaxLoader" /></form></div>';
}
$pollAnswersHtml = $pollAnswersHtml . '<input name="pollID" type="hidden" id="pollID" value="' . $pollID .'" /><li><input name="pollAnswerID" id="pollRadioButton' . $pollAnswerID . '" type="radio" value="' . $pollAnswerID . '" /> ' . $pollAnswerValue .'<span id="pollAnswer' . $pollAnswerID . '"></span></li>';
$pollAnswersHtml = $pollAnswersHtml . '<li class="pollChart pollChart' . $pollAnswerID . '"></li>';
}
echo $pollStartHtml . $pollAnswersHtml . $pollEndHtml;
}
function getPollID($pollAnswerID){
$query = "SELECT pollID FROM tblpollanswers WHERE pollAnswerID = ".$pollAnswerID." LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
return $row['pollID'];
}
function getPollResults($pollID){
$colorArray = array(1 => "#ffcc00", "#00ff00", "#cc0000", "#0066cc", "#ff0099", "#ffcc00", "#00ff00", "#cc0000", "#0066cc", "#ff0099");
$colorCounter = 1;
$query = "SELECT pollAnswerID, pollAnswerPoints FROM tblpollanswers WHERE pollID = ".$pollID."";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
{
if ($pollResults == "") {
$pollResults = $row['pollAnswerID'] . "|" . $row['pollAnswerPoints'] . "|" . $colorArray[$colorCounter];
} else {
$pollResults = $pollResults . "-" . $row['pollAnswerID'] . "|" . $row['pollAnswerPoints'] . "|" . $colorArray[$colorCounter];
}
$colorCounter = $colorCounter + 1;
}
$query = "SELECT SUM(pollAnswerPoints) FROM tblpollanswers WHERE pollID = ".$pollID."";
$result = mysql_query($query);
$row = mysql_fetch_array( $result );
$pollResults = $pollResults . "-" . $row['SUM(pollAnswerPoints)'];
echo $pollResults;
}
//VOTE START
if ($action == "vote"){
$strSQL = "INSERT INTO tblpdorm ";
$strSQL .="(pollID,member_user)";
$strSQL .="VALUES ";
$strSQL .="('".getPollID($pollAnswerID)."','".$_SESSION['login_true_google']."')";
$objQuery = mysql_query($strSQL);
$query = "UPDATE tblpollanswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = ".$pollAnswerID."";
mysql_query($query) or die('Error, insert query failed');
setcookie("poll" . getPollID($pollAnswerID), 1, time()+259200, "/");
getPollResults(1);
}
//VOTE END
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-12-07 10:35:33 |
By :
buraratn |
View :
940 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองตรวจสอบ
$query58 = "SELECT * FROM tblpolls WHERE dorm_id = '".$_GET['id']."' ORDER By pollID ASC";
ถ้า dorm_id เป็น int ก็ไม่ควรจะเป็น dorm_id = '".$_GET['id']."' ควรที่จะเป็น dorm_id = ".$_GET['id']."
ลองดูละกันนะ
|
|
|
|
|
Date :
2011-12-07 12:48:38 |
By :
onedan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MySQL ไม่น่าจะมีปัญหาเรื่อง Data Type ครับ ว่าแต่ Error บรรทัดไหนครับ
|
|
|
|
|
Date :
2011-12-07 12:59:57 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|