Daney11 Posted January 28, 2007 Share Posted January 28, 2007 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]<?phpfunction 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]<?phpinclude_once('database_connect/database_connect.php'); // This Connects To The MySQL DatabaseConnectDatabase();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 8Warning: 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 11Any help would be great, thanks guys. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 It helps if you show the code for the page that is producing the error, where you call TotalTeams(); Quote Link to comment Share on other sites More sharing options...
.josh Posted January 28, 2007 Share Posted January 28, 2007 that error means that your function is expecting another argument to be passed to it, but you are only passing 1 argument. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 28, 2007 Author Share Posted January 28, 2007 The page is.[code]<?phpinclude_once('database_connect/database_connect.php'); include_once('included_files/total_goals.php'); ConnectDatabase();TotalsTeam();echo $team_draw_total;?>[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 Well, you're not passing it anything to be $db, so...that's why you're getting the error that you're not passing it an argument. Quote Link to comment Share on other sites More sharing options...
Daney11 Posted January 28, 2007 Author Share Posted January 28, 2007 But i'm selecting from the database.$strQuery = "SELECT * FROM teams WHERE team_id > 0";$result = mysql_query($strQuery,[b]$db[/b]) or die(mysql_error());$myrow = mysql_fetch_array($result);This is confusing me lol Quote Link to comment Share on other sites More sharing options...
.josh Posted January 28, 2007 Share Posted January 28, 2007 okay you're over-complicating it. Look at this example:[code]function blah($something) { echo $something;}blah("foobar"); // will call function blah, which will echo "foobar"blah(); // will produce an error, because it expects an argument to be passed[/code] Quote Link to comment 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.