Jump to content

Archived

This topic is now archived and is closed to further replies.

stormflurry

Need help passing arrays out of a class

Recommended Posts

Hi All,

I'm trying to become a smarter programmer I guess by changing all of the files that I previously used as scripts to php classes. I'm having trouble moving arrays out of the class once I've selected the appropriate data. Here is the code below.

This is my class. What the class is supposed to do for me is connect me up to the data base set the date range that I want to look at and then select the appropriate information from the table. It currently does all of these things.

class select {

function DBSelect ($db_name) {

define('MYSQL_DB_USER','root');
define('MYSQL_DB_PASSWORD','----');
define('MYSQL_DB_HOST','localhost');
define('MYSQL_DB_NAME',$db_name);

$dbc = mysql_connect (MYSQL_DB_HOST,MYSQL_DB_USER,MYSQL_DB_PASSWORD);
mysql_select_db (MYSQL_DB_NAME);

}

function SetDate () {

if ($_GET['FirstSelectDay'] && $_GET['FirstSelectMonth'] && $_GET['FirstSelectYear']) {

$this->$NewDate = $_GET['FirstSelectYear'];
$this->$NewDate .= "-";
$this->$NewDate .= $_GET['FirstSelectMonth'];
$this->$NewDate .= "-";
$this->$NewDate .= $_GET['FirstSelectDay'];
return $this->newDate;

} else {

$this->$NewDate = date("Y-m-d");
return $this->newDate;

}

}

function GetResults ($procedure) {

$this->DBSelect('tndcs');
$this->setDate();
$date = $this->$newDate;

$this->$procedure = 'procedures/';
$this->$procedure .= $procedure;
$this->$procedure .= '.inc';

include_once($this->$procedure);

$result = @mysql_query($query);

if ($result) {

while($row = mysql_fetch_array($result,MYSQL_NUM)) {

$this->values = $row;

}

mysql_free_result($result);
return $this->values;


} else {

$error = mysql_error();
$error .= "\n\nUser id: {$_SESSION['user_id']}";
$message = "<p>$error<br>There has been an application error the server administrator has been contacted.</p>";
echo $message;
mail ("stormflurry@gmail.com","Error in Action $action",$error,"From: {$_SESSION['user_email']}");

}

}

}

My issue is that I can only get a single row back to the main script so if I have multiple rows of data I'm stuck. I've been pounding on this issue for many days and the only thing that I can come up with is placing the code that formats the selected data inside a subclass of select (). Basically make an extension that holds both the query that I want to run and the formatting that I need to apply to the results.

if I run the query in the main script getting multiple rows is no problem I do my standard

while ($row = mysql_fetch_array($result,MYSQL_NUM)) {}

I guess what i need to know how to do is this.

while ($values = $sql->getResults2('select_order_total')) {}

but this doesn't work.

Help please do I write unique extendor classes for each query which I feel is a mess or is there some better way.

Thanks,

Matt







Share this post


Link to post
Share on other sites
Change

[code]while($row = mysql_fetch_array($result,MYSQL_NUM)) {

              $this->values = $row;

}[/code]

to

[code]while($row = mysql_fetch_array($result,MYSQL_NUM)) {

               $this->values[] = $row;

}[/code]

Share this post


Link to post
Share on other sites

×

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.