Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am I loosing My Mind?

Status
Not open for further replies.

ekbranson

Programmer
Jan 12, 2004
52
US
Ok, I have a simple class that I will use for javascript based client side paging. For some reason my class is setting all the class variables to the same value when any one of them is set. Am I loosing my mind?

Here is the code:

<?php

class ClientPaging{

var $rowsPerPg;
var $currentPg;
var $numCols;
var $numRecs;
var $maxPg;
var $qry;

function ClientPaging($rows=10, $qry=""){

$this->$rowsPerPg = $rows;
$this->$currentPg = 1;
$this->$numCols = 0;
$this->$numRows = 0;
$this->$maxPg = 0;

$this->$qry = $qry;
if ($qry <> "")
$this->initalize($qry);

}

function initalize($qry){
//The db_connect here is in a seperate file, it works.
if(!$conn = db_connect()){
echo "No connection";
return false;
}
else
{
$result = mysql_query($qry) or die('Error, query failed');
//The qry I am using returns 22 rows and 4 cols

$this->$numCols = mysql_num_fields($result);
$this->$numRows = mysql_num_rows($result);
$this->maxPg = ($this->$numRows/$this->$numCols);
}
//So I should see
//10
//4
//22
echo $this->$rowsPerPg."<BR>";
echo $this->$numCols."<BR>";
echo $this->$numRows;
}
}
But
When instantiated I get this:

22
22
22

Any one see something I'm missing?
 
Well, one thing I see is that you are setting your object vars you are using:
$this->$var_name = value;

and I believe you want it to be:
$this->var_name = value;

Notice the absence of the second '$' infront of the object var name...

HTH,
Itshim
 
That was it thanks, I can't believe I missed that.

I guess I should cut down on the coffee.
 
Happens to me all the time, but...the answer is not less coffee it is more coffee. Once your eyes vibrate at the same frequency as the monitor you start to see things more clearly :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top