Jump to content

Function Help


Daney11

Recommended Posts

Hey Guys,

This one is getting to me...

I want to create a function that i can use in other script.

My database connect script is within a function which is..
[code]
<?php
function ConnectDatabase()

{

global $db;
$db = mysql_connect("localhost","root","") or die("Unable To Connect To The MySQL Database");
mysql_select_db("database_name", $db) or die("Unable To Select The Database");
?>
}
[/code]

When i write ConnectDatabase(); within the scripts it works perfectly, however. The problem that i have having is that when i add something else in a function for example

[b]total_goals.php[/b]
[code]
<?php

include_once('database_connect/database_connect.php'); // This Connects To The MySQL Database

ConnectDatabase();

function TotalsTeam($db) {

$strQuery = "SELECT * FROM teams WHERE team_id > 0";
$result = mysql_query($strQuery,$db) or die(mysql_error());
$myrow = mysql_fetch_array($result);

$team_home_win = $myrow['team_home_win'];
$team_away_win = $myrow['team_away_win'];
$team_win_total = ($team_home_win + $team_away_win);

$team_home_draw = $myrow['team_home_draw'];
$team_away_draw = $myrow['team_away_draw'];
$team_draw_total = ($team_home_draw + $team_away_draw);

$team_home_lose = $myrow['team_home_lose'];
$team_away_lose = $myrow['team_away_lose'];
$team_lose_total = ($team_home_lose + $team_away_lose);

$team_home_goals_for = $myrow['team_home_goals_for'];
$team_away_goals_for = $myrow['team_away_goals_for'];
$team_total_goals_for = ($team_home_goals_for + $team_away_goals_for);

$team_home_goals_against = $myrow['team_home_goals_against'];
$team_away_goals_against = $myrow['team_away_goals_against'];
$team_total_goals_against = ($team_away_goals_for + $team_away_goals_against);

}

?>
[/code]

And i include the file and use TotalTeams(); in another script, it gives me this abuse...

Warning: Missing argument 1 for totalsteam() in c:\program files\easyphp1-8\www\pro football manager\included_files\total_goals.php on line 8

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in c:\program files\easyphp1-8\www\pro football manager\included_files\total_goals.php on line 11


Any help would be great, thanks guys.
Link to comment
https://forums.phpfreaks.com/topic/36105-function-help/
Share on other sites

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.