I must be missing something utterly simple. I have a script where I include a php file and it reads from the DB just fine but when I call it again, it has problems and I have no idea why. Below is some of the code:
first I have a class that I include as an includes file which makes accessing the DB easier:
class sql_driver {
var $database="ladder";
var $host="localhost";
var $user="test";
var $pass="testes";
var $queryID = "";
var $ID = "";
function connect() {
$this->ID = mysql_connect( $this->host ,
$this->user , $this->pass);
if ( !mysql_select_db($this->database, $this->ID) )
echo ("Error ".$this->database." cannot be found in the
database server");
}
etc....
Now I include this as so...
include ("../Drivers/mySQL.php");
and make use of it through another file that I include...
<?php
global $output;
include("../Skins/skin1/viewLadderSkin.php");
$DB->query("select M.fname, M.lname, L.rank, L.wins, L.losses from member as M join league_coedsquash as L on M.mem_id=L.mem_id order by L.rank;");
$numberRows = $DB->getNumberRows();
$output .= startLadderTable();
for ($i = 0; $i < $numberRows; $i++)
{
$row = $DB->getRow();
$output .= displayLadderRow($row['rank'], $row['fname']." ".$row['lname'], $row['wins'], $row['losses']);
}
$output .= endLadderTable();
?>
Up to here we are doing fine, but when we call the page again, I get the following error.
Fatal error: Call to a member function on a non-object in c:\apache group\apache\htdocs\proclub\ladder\sources\viewLadder2.php on line 5
And line 5 is where I use the $DB->query instance. Now refreshing the page doesn't cause a problem but calling it via the following cause a problem:
$output .= "<center><Font size = +2>Co-Ed Squash Ladder</font></center><BR>\n";
$output .= "<A HREF=\"main.php\">Home</a>\n";
$output .= "<A HREF=\"main.php?action=report&code=0\">Report a game</a>\n";
$output .= "<A HREF=\"main.php?action=register&code=0\">add user (temp until signups added)</a>\n";
$action = $HTTP_GET_VARS['action'];
$choice = array(
"viewLadder" => "viewLadder2",
"report" => "reportGame3",
"register" => "register",
);
// Check to make sure the array key exits..
if (! isset($choice[ $action ]) )
{
$action = "viewLadder";
}
$whatToDo = $choice[ $action ];
include ($whatToDo.".php");
Can someone please help? I'm at my wits end and it's a short ride on a short bus.