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