Jump to content

how do i call a function again!!


j4ymf

Recommended Posts

hello folks

 

its been some time since ive used php, but in starting to play again.

ive got this function and i want to be able to use the $totaltally else where as well so i need to call the function early, but ive forgot where to put the call function.

 

can you please help

thanks jason

 

 

 

//.....///.......///.........////........../////........///....../////............////..............

function check_team_totaltally($player_1, $player_2, $player_3, $player_4, $player_5, $player_6, $player_7, $player_8, $player_9, $player_10, $player_11) {

include("passwords.inc");

$connection = mysql_connect($host, $user,$password) or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection) or die ("Couldn't select database.");

$query  = "SELECT sum(price) 'total' ";
$query .= "FROM dreamteam ";
$query .= "WHERE dreamteam.id ";
$query .= "IN ('$player_1', '$player_2', '$player_3', '$player_4', '$player_5', '$player_6', '$player_7', '$player_8', '$player_9', '$player_10', '$player_11')";
  
  //  echo "<p>check_team_total() >>> " . $query . "<p>";     
  //(remove the // ehen checking for errors)

$result = mysql_query($query) or die ("<font color='#ffff00' size='4'>Error! checking your team total!    (3)");

$total = mysql_fetch_assoc($result);



if ($total1['total'] > 50) { // change to 40 for normal seasons 50 for the world cup
	global $totaltally;
	$totaltally = $total1['total'];		
	return False;
} else {
	return True;
}

$returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11);

echo " $totaltally " ;	


}



//.....///.......///.........////........../////........///....../////............////..............

 

Link to comment
https://forums.phpfreaks.com/topic/169440-how-do-i-call-a-function-again/
Share on other sites

Well, you're doing like

$returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11);

so you could just do

$totaltally = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11);

instead.

 

Also, I would refactor your function to take an array instead of 11 separate elements.

This is the code you use to call the function

$returnValue = check_team_totaltally($player_1,$player_2,$player_3,$player_4,$player_5,$player_6,$player_7,$player_8,$player_9,$player_10,$player_11);

 

Use that code to call that function again.

 

However your function can be made a lot better.

include("passwords.inc");

   $connection = mysql_connect($host, $user,$password) or die ("Couldn't connect to server.");
   $db = mysql_select_db($database, $connection) or die ("Couldn't select database.");

 

Personally I would have all that in single file called db.php. Whenever you want to connect to MySQL use

require_once "db.php"

 

WARNING having code in .inc files can be read as plain text. So if someone found out where your passwords.inc file is by going to yoursite.com/passwords.inc they will be able to read your database credentials. You should end all files in .php to prevent this, ed file.inc.php

 

This is not recommend

      global $totaltally;
      $totaltally = $total1['total'];      
      return False;

 

You should change it to

return $total1['total'];

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.