Jump to content
php.lv forumi

mysql_fetch_array... bolean...


Kracker

Recommended Posts

Sveiki! Palīdzat ar skriptu, nu kaut pakaries, bet rāda kļūdu - Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home_new/project/public_html/modules/poll/inc/functions.php on line 27

 

Line 27 ir while($row = mysql_fetch_array($result, MYSQL_ASSOC))

 

function getPoll($pollID){
$query  = "SELECT * FROM polls LEFT JOIN pollAnswers ON polls.pollID = pollAnswers.pollID WHERE polls.pollID = " . $pollID . " ORDER By pollAnswerListing ASC";
$result = mysql_query($query);
//echo $query;jquery
if($_SESSION["radamais"]!="'".$pollID."'"){
$_SESSION["radamais"] = $pollID;
}

$pollStartHtml = '';
$pollAnswersHtml = '';


while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
...

Edited by Kracker
Link to comment
Share on other sites

Pilns kods. Uz localhost-a man viss strādāja ideāli, bet kā uzliku uz servera, tā rāda kļūdu.

 

function getPoll($pollID){
$res  = mysql_query("SELECT * FROM polls LEFT JOIN pollAnswers ON polls.pollID = pollAnswers.pollID WHERE polls.pollID = " . $pollID . " ORDER By pollAnswerListing ASC");
//echo $query;jquery
if($_SESSION["radamais"]!="'".$pollID."'"){
$_SESSION["radamais"] = $pollID;
}

$pollStartHtml = '';
$pollAnswersHtml = '';


while($row = mysql_fetch_array($res))
{
 $pollQuestion   = $row['pollQuestion'];
 $pollAnswerID   = $row['pollAnswerID'];
 $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="Balsot" /> <span id="pollMessage"></span><img src="ajaxLoader.gif" alt="Ajax Loader" id="pollAjaxLoader" /></form></div>';
 }
 $pollAnswersHtml = $pollAnswersHtml . '<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){
$result  = mysql_query("SELECT pollID FROM pollAnswers WHERE pollAnswerID = ".$pollAnswerID." LIMIT 1");
$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 pollAnswers 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 pollAnswers WHERE pollID = ".$pollID."";
$result = mysql_query($query);
$row = mysql_fetch_array( $result );
$pollResults = $pollResults . "-" . $row['SUM(pollAnswerPoints)'];
echo $pollResults;
}

//VOTE START
if ($action == "vote"){

if (isset($_COOKIE["poll" . getPollID($pollAnswerID)])) {
 echo "voted";
} else {
 $query  = "UPDATE pollAnswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = ".$pollAnswerID."";
 mysql_query($query) or die('Error, insert query failed');
 setcookie("poll" . getPollID($pollAnswerID), "", time()+7776000, "/~adrese/", ".adrese.lv");
 getPollResults($_SESSION["radamais"]);
 unset($_SESSION["radamais"]);
}
}

Link to comment
Share on other sites

 

Bet kā tu vari izskaidrot to, ka uz localhost strādā, bet uz servera, kad uzliek nestrādā?

a) nepareiza DB parole, vai uservards, vai arii nepareizs serveris - uz serveriem bieži vien nav loclhost, bet ir konkrēts db serveris .

b) tabulas uz tava localhost un servera ir dažādas - vai arī kāda tabula trūks, vai trūkst kāda no kolonnām,

Link to comment
Share on other sites

a) nepareiza DB parole, vai uservards, vai arii nepareizs serveris - uz serveriem bieži vien nav loclhost, bet ir konkrēts db serveris .

b) tabulas uz tava localhost un servera ir dažādas - vai arī kāda tabula trūks, vai trūkst kāda no kolonnām,

 

Abi norādītie punkti ir pareizi, takš nevar būt ka viss strādā uz localhost, bet šis pēlšņi nestrādās un tabulas, kolonas arī netrūkst, tikko pārbaudīju. :) Tādēļ saku, kaut pakaries, bet nestrādā. :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...