Jump to content

Recommended Posts

<?php
require_once ('classes/database.class.php');
class cases extends database {
function __construct($caseID) {
	# Get the case details
	$sql = "SELECT * FROM cases WHERE caseID = '$caseID'";
	$result = $this->query($sql);
	$row = $this->fetchArray($result);
	foreach($row as $key=>$value) {
		$this->$key = $value;
	}
}
}?>

 

...Throws this:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /*/classes/database.class.php on line 52

 

Warning: Invalid argument supplied for foreach() in /*/classes/cases.class.php on line 11

 

Notice: Undefined property: cases::$plaintiff in /*/test.php on line 11

 

vs.

 

Notice: Undefined property: cases::$defendant in /*/test.php on line 13

 

However, This DOES work:

<?php
class cases extends database {
function getCaseInfo($caseID) {
	# Get the case details
	$sql = "SELECT * FROM cases WHERE caseID = '$caseID'";
	$result = $this->query($sql);
	$row = $this->fetchArray($result);
	foreach($row as $key=>$value) {
		$this->$key = $value;
	}
}
}
?>

 

Test.php looks like this;

<?php
/**
* Test file
*/
error_reporting(E_ALL);

// Get required files
require_once 'classes/cases.class.php';

$T = new cases('3');
echo $T->plaintiff;
echo "<br/>vs.<br/>";
echo $T->defendant;

/* Or */

$T = new cases();
$info = $T->getCaseInfo('3');
echo $T->plaintiff....
?>

does the database class have a __constuct function that needs to be run? if so, your non-working copy is not running it. try updating it to this:

<?php
require_once ('classes/database.class.php');
class cases extends database {
   function __construct($caseID) {
      # Run parent
      parent::__construct();
      # Get the case details
      $sql = "SELECT * FROM cases WHERE caseID = '$caseID'";
      $result = $this->query($sql);
      $row = $this->fetchArray($result);
      foreach($row as $key=>$value) {
         $this->$key = $value;
      }
   }
}?>

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.