472,951 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,951 software developers and data experts.

class does not return a value

My first time working with a PHP class, and after 6 hours of working out the
kinks I am unable to return a value from the class, so now I appeal to the
general audience what on earth did I do wrong this time?

This is the code the retrieves the values:

if (($hasRegistered || $hasPreRegistered) && !empty($uplinenumber)) {
// CHECK TO SEE IF UPLINE NUMBER IS A VALID NUMBER
$regNumberGenerator = new RegNumberGenerator($uplinenumber, $email,
$dbConn);
if (!$regNumberGenerator->isValidUplinenumber()) {
$hasRegistered = 0; $hasPreRegistered = 0;
$errorMsg .= $font . '<font color=cc0000><li>Du måste skicka geltig
upline nr., takk!' .
'</li></font></font><p>';
// ERROR PRODUCED UPON REG OR PRE-REG MODE - FORM WILL BE REPOPULATED BY
$_POST ELEMENTS
// NO NEED FOR DB ANY FURTHER

@mysql_free_result($query); // FREE RESOURCES BUT SUPPRESS WARNINGS IF
NON-SELECT QUERY
mysql_close($dbConn); // CLOSE DB CONNECTION
} else {
$registrationNumber = $regNumberGenerator->getRegNumber();
$registrationNumberForUsername =
$regNumberGenerator->getRegNumberDecDigits($registrationNumber);
$registrationNumberForEmail =
$regNumberGenerator->getRegNumberDecDigits($registrationNumber, '-');
}
}

And here is the class itself:

/*--------------------------------------------------------------------------
-----------------
Class RegNumberGenerator - this class consists of the following:

1. Method isValidUplinenumber - Boolean return if the upline number is a
valid one
according to a db call

2. Method getRegNumber - String method to return the hexidecimal
registration number
3. Method getRegNumberDecDigits - String method to return the reg number
as decimal digits
4. Private method hasFoundNextAvailRegNumber - Boolean method that
searches for the inputted
number as a registration
number in the db
5. Private method incrUplinenumber - String method to increase
next-to-last digit of
upline number by 1 (to get to the
next "leg")

Input parameters:

1. $dbConn - your database connection resource link
2. $uplinenumber - your upline number
3. $email - your email address
--------------------------------------------------------------------------
------------------*/
class RegNumberGenerator {

// STRING TO HOUSE GENERATED REGISTRATION NUMBER BASED ON UPLINE #
var $paddedUplinenumber = '';
var $regNumber = '';
var $canStopMethod = 0; // BOOLEAN TO DETERMINE TO STOP SEARCHING FOR
NEXT VALID REG #

// CONSTRUCTOR
function RegNumberGenerator($uplinenumber, $email, $dbConn) {
$this->uplinenumber = $uplinenumber;
$this->email = $email;
$this->dbConn = $dbConn;
}

// BOOLEAN METHOD
function isValidUplinenumber() {

// CHECK TO SEE IF SINGLE-DIGIT UPLINENUMBER IS NUMERIC VALUE ONLY
if (strlen($this->uplinenumber) == 0 ||
(strlen($this->uplinenumber) == 1 &&
!is_numeric($this->uplinenumber))
) {
$canStopMethod = 1;
return 0;
}

// CHECK TO SEE IF UPLINENUMBER IS VALID (IS HEXADECIMAL NUMBER STRING)
if (preg_match('/[^a-fA-F0-9]+/i', $this->uplinenumber) &&
!$canStopMethod) {
$canStopMethod = 1;
return 0;
}

// CHECK TO SEE THAT IF THIS IS A TOP UPLINENUMBER THAT IT IS A VALID
TOP UPLINE NUMBER IN DB
if (strlen($this->uplinenumber) == 1 && !$canStopMethod) {
$sql = 'SELECT nnet_user_email FROM nnet_top_uplinenumber ' .
'WHERE nnet_user_uplinenumber = ' . (int)$this->uplinenumber;
$query = mysql_query($sql, $this->dbConn) or die('Could not perform
query');
if (mysql_num_rows($query) == 0) {
$canStopMethod = 1;
return 0; // NOT VALID TOP UPLINENUMBER
}
}

// CHECK TO SEE IF SINGLE-DIGIT UPLINENUMBER WAS ENTERED BY A TOP USER
(RAGNAR, DAVID, ETC)
if (strlen($this->uplinenumber) == 1 && !$canStopMethod) {
if ($row = mysql_fetch_row($query)) {
$topUserEmail = $row[0]; // OBTAIN TOP USER EMAIL ADDRESS FOR
COMPARISON
$sql = 'SELECT nnet_userid FROM nnet_usermetadata ' .
'WHERE nnet_user_email = \'' . $this->email . '\' ' .
' AND nnet_user_registrationnumber = \'' . $this->uplinenumber
.. '\' ';
$query = mysql_query($sql, $this->dbConn) or die('Could not perform
query #2');
if (mysql_num_rows($query) > 0) {
// THEY ARE A TOP USER BUT ALREADY FOUND IN USERMETADATA - RETURN
FALSE
$canStopMethod = 1;
return 0;
} elseif (strcmp($topUserEmail, $this->email) == 0) {
// THEY ARE A TOP USER NOT FOUND YET IN USERMETADATA - SET REG # TO
UPLINE # & SET TRUE
$regNumber = $this->uplinenumber;
$canStopMethod = 1;
return 1;
}
}
}

// CHECK TO SEE IF THIS IS SOMEONE'S REGISTRATION NUMBER
if (!$canStopMethod &&
!$this->hasFoundNextAvailRegNumber($this->uplinenumber)) {
$canStopMethod = 1;
return 0;
}

// THIS IS SOMEONE'S REG # - WE NOW HAVE TO CALCULATE THE NEXT AVAILABLE
LEG
if (!$canStopMethod) {
$paddedUplinenumber .= $this->uplinenumber . '11';
if (!$this->hasFoundNextAvailRegNumber($paddedUplinenumber) ) {
$canStopMethod = 1;
return 0;
}
// KEEP INCREASING NEXT_TO_LAST DIGIT BY 1 UNTIL NO LONGER FOUND IN DB
AS REG #
while ($this->hasFoundNextAvailRegNumber($paddedUplinenumber) )
$paddedUplinenumber = $this->incrUplinenumber($paddedUplinenumber);
$regNumber = $paddedUplinenumber;
return 1;
}
}
// STRING METHOD
function incrUplinenumber($myUplinenumber) {
$hexDigit = substr($myUplinenumber, strlen($myUplinenumber) - 2, 1); //
NEXT_TO_LAST DIGIT
$nextDecDigit = (int)hexdec($hexDigit) + 1;
return substr($myUplinenumber, 0, strlen($myUplinenumber) - 2) .
dechex($nextDecDigit) .
substr($myUplinenumber, strlen($myUplinenumber) - 1, 1);
}
// BOOLEAN METHOD
function hasFoundNextAvailRegNumber($paddedUplinenumber) {
global $dbConn;
$sql = 'SELECT nnet_userid FROM nnet_usermetadata ' .
'WHERE nnet_user_registrationnumber = \'' . $paddedUplinenumber .
'\' ';
$query = mysql_query($sql, $dbConn) or die('Could not perform query
#3');
if (mysql_num_rows($query) == 0) {
// NO ONE HAS THIS UPLINE # AS THEIR REG # - INVALID UPLINE NUMBER
return 0;
} else {
return 1;
}
}
// STRING METHOD TO RETURN HEX REG NUMBER
function getRegNumber() {
return $regNumber;
}

// STRING METHOD TO RETURN DECIMAL-DIGITS REG NUMBER (NOT TRUE NUMBER)
WITH OPTIONAL CHAR
// DIVIDER

function getRegNumberDecDigits($myRegNumber, $divider = '') {
for ($i = 0; $i < strlen($myRegNumber); $i++)
$decRegNumber .= '' . hexdec(substr($myRegNumber, $i, 1)) . $divider;
return $decRegNumber;
}
}
//---END OF
CLASS-----------------------------------------------------------------------
----

Phil
Jul 16 '05 #1
3 4464
Phil Powell <so*****@erols.com> wrote:
My first time working with a PHP class, and after 6 hours of working out
the kinks I am unable to return a value from the class, so now I appeal to
the general audience what on earth did I do wrong this time?
[snip]
// STRING METHOD TO RETURN HEX REG NUMBER
function getRegNumber() {
return $regNumber;
}


Shouldn't this be:

function getRegNumber() {
return $this->regNumber;
}

HTH;
JOn
Jul 16 '05 #2
Yep, figured that one out on my own. I can't find any online documentation
on PHP classes, where should I look? www.php.net is Macedonian to me at
times.

Phil

"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:bj************@ID-175424.news.uni-berlin.de...
Phil Powell <so*****@erols.com> wrote:
My first time working with a PHP class, and after 6 hours of working out
the kinks I am unable to return a value from the class, so now I appeal to the general audience what on earth did I do wrong this time?


[snip]
// STRING METHOD TO RETURN HEX REG NUMBER
function getRegNumber() {
return $regNumber;
}


Shouldn't this be:

function getRegNumber() {
return $this->regNumber;
}

HTH;
JOn

Jul 16 '05 #3
Phil Powell <so*****@erols.com> wrote:
Yep, figured that one out on my own. I can't find any online
documentation on PHP classes, where should I look? www.php.net is
Macedonian to me at times.


Google is generally a good start ;)
Here is a good article covering classes in PHP:

Part 1:
http://www.zend.com/zend/tut/tutorial-johnson.php
Part2:
http://www.zend.com/zend/tut/tutorial-johnson2.php

HTH;
JOn
Jul 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: syd | last post by:
In my project, I've got dozens of similar classes with hundreds of description variables in each. In my illustrative example below, I have a Library class that contains a list of Nation classes. ...
9
by: Erick Sasse | last post by:
How can I make a method that takes a class (not an instance) as parameter? And I want this parameter to accept only Windows Form classes, ie classes that inherits System.Windows.Forms.Form. ...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
10
by: mast2as | last post by:
Is it possible to limit a template class to certain types only. I found a few things on the net but nothing seems to apply at compile time. template <typename T> class AClass { public:...
3
by: Miro | last post by:
First off...thanks in advance for getting me this far. Sorry for all these class posts but im having a heck of a time here trying to get something to work, and have finally got it to work (...
6
by: Erick | last post by:
I've created a class called Procs and a collection class called Processes which uses a hastable object to store the Procs. Now i want to enumerate with the "For each" to extract all the Procs in...
3
by: ryan.gilfether | last post by:
I have a problem that I have been fighting for a while and haven't found a good solution for. Forgive me, but my C++ is really rusty. I have a custom config file class: class ConfigFileValue...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
16
by: John Doe | last post by:
Hi, I wrote a small class to enumerate available networks on a smartphone : class CNetwork { public: CNetwork() {}; CNetwork(CString& netName, GUID netguid): _netname(netName),...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.