SmileyWar Posted January 15, 2012 Share Posted January 15, 2012 Hiya guys, I'm having trouble i cant call on the function correct <?php $i = "16"; function getResults($i) { some code } getResults($i) ?> But placing a variable in a function call is not working it will work with getResults(16) Btw i'm new with the function protocols Thanks for the help in advance! Quote Link to comment https://forums.phpfreaks.com/topic/255082-function-getresultsi/ Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 Well "16" is a numerical string, not an integer. We really need to see how your code is handling it's argument. Quote Link to comment https://forums.phpfreaks.com/topic/255082-function-getresultsi/#findComment-1307936 Share on other sites More sharing options...
SmileyWar Posted January 15, 2012 Author Share Posted January 15, 2012 Hiya here is the code below <?php 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"){ $result = mysql_query("SELECT * FROM pollIp WHERE pollIp = '$ip' && pollID = '".$pollAnswerID."'"); if (!$result) { die('There was a problem executing the query'); } $number_of_rows = mysql_num_rows($result); if ($number_of_rows > 0) { getPollResults($prepollID); } else { $query = "UPDATE pollAnswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = ".$pollAnswerID.""; mysql_query($query) or die('Error, insert query failed'); mysql_query("INSERT INTO pollIp (pollID, pollIp) VALUES ('".$pollAnswerID."', '$ip') ") or die(mysql_error()); mysql_query("INSERT INTO stats(vis_ip, vis_agent, vis_lang, vis_ref) values ('".$_SERVER['REMOTE_ADDR']."', '".$_SERVER['HTTP_USER_AGENT']."', '".$_SERVER['HTTP_ACCEPT_LANGUAGE']."', '".$_SERVER['HTTP_REFERER']."')") or die(mysql_error()); getPollResults($prepollID); } } //VOTE END ?> $prepollID is the same as $pollID Quote Link to comment https://forums.phpfreaks.com/topic/255082-function-getresultsi/#findComment-1307937 Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 Hiya here is the code below <?php 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"){ $result = mysql_query("SELECT * FROM pollIp WHERE pollIp = '$ip' && pollID = '".$pollAnswerID."'"); if (!$result) { die('There was a problem executing the query'); } $number_of_rows = mysql_num_rows($result); if ($number_of_rows > 0) { getPollResults($prepollID); } else { $query = "UPDATE pollAnswers SET pollAnswerPoints = pollAnswerPoints + 1 WHERE pollAnswerID = ".$pollAnswerID.""; mysql_query($query) or die('Error, insert query failed'); mysql_query("INSERT INTO pollIp (pollID, pollIp) VALUES ('".$pollAnswerID."', '$ip') ") or die(mysql_error()); mysql_query("INSERT INTO stats(vis_ip, vis_agent, vis_lang, vis_ref) values ('".$_SERVER['REMOTE_ADDR']."', '".$_SERVER['HTTP_USER_AGENT']."', '".$_SERVER['HTTP_ACCEPT_LANGUAGE']."', '".$_SERVER['HTTP_REFERER']."')") or die(mysql_error()); getPollResults($prepollID); } } //VOTE END ?> $prepollID is the same as $pollID Couple things, since $ pollId needs to be an int, type cast it into an int before using it in your function. You check for $pollResults being empty, when the variable does not yet exist in the function. I'm assuming you want to output the difference, if you are doing math to $pollResults, remove the quotes around the subtraction operators. Quote Link to comment https://forums.phpfreaks.com/topic/255082-function-getresultsi/#findComment-1307939 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.