Jump to content

function getResults($i)


SmileyWar

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.