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 (($hasRegistere d || $hasPreRegister ed) && !empty($uplinen umber)) {
// CHECK TO SEE IF UPLINE NUMBER IS A VALID NUMBER
$regNumberGener ator = new RegNumberGenera tor($uplinenumb er, $email,
$dbConn);
if (!$regNumberGen erator->isValidUplinen umber()) {
$hasRegistered = 0; $hasPreRegister ed = 0;
$errorMsg .= $font . '<font color=cc0000><l i>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_res ult($query); // FREE RESOURCES BUT SUPPRESS WARNINGS IF
NON-SELECT QUERY
mysql_close($db Conn); // CLOSE DB CONNECTION
} else {
$registrationNu mber = $regNumberGener ator->getRegNumber() ;
$registrationNu mberForUsername =
$regNumberGener ator->getRegNumberDe cDigits($regist rationNumber);
$registrationNu mberForEmail =
$regNumberGener ator->getRegNumberDe cDigits($regist rationNumber, '-');
}
}
And here is the class itself:
/*--------------------------------------------------------------------------
-----------------
Class RegNumberGenera tor - this class consists of the following:
1. Method isValidUplinenu mber - 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 getRegNumberDec Digits - String method to return the reg number
as decimal digits
4. Private method hasFoundNextAva ilRegNumber - Boolean method that
searches for the inputted
number as a registration
number in the db
5. Private method incrUplinenumbe r - 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 RegNumberGenera tor {
// STRING TO HOUSE GENERATED REGISTRATION NUMBER BASED ON UPLINE #
var $paddedUplinenu mber = '';
var $regNumber = '';
var $canStopMethod = 0; // BOOLEAN TO DETERMINE TO STOP SEARCHING FOR
NEXT VALID REG #
// CONSTRUCTOR
function RegNumberGenera tor($uplinenumb er, $email, $dbConn) {
$this->uplinenumber = $uplinenumber;
$this->email = $email;
$this->dbConn = $dbConn;
}
// BOOLEAN METHOD
function isValidUplinenu mber() {
// CHECK TO SEE IF SINGLE-DIGIT UPLINENUMBER IS NUMERIC VALUE ONLY
if (strlen($this->uplinenumber ) == 0 ||
(strlen($this->uplinenumber ) == 1 &&
!is_numeric($th is->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_upline number ' .
'WHERE nnet_user_uplin enumber = ' . (int)$this->uplinenumber ;
$query = mysql_query($sq l, $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_usermetada ta ' .
'WHERE nnet_user_email = \'' . $this->email . '\' ' .
' AND nnet_user_regis trationnumber = \'' . $this->uplinenumber
.. '\' ';
$query = mysql_query($sq l, $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($topUse rEmail, $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 (!$canStopMetho d &&
!$this->hasFoundNextAv ailRegNumber($t his->uplinenumber )) {
$canStopMethod = 1;
return 0;
}
// THIS IS SOMEONE'S REG # - WE NOW HAVE TO CALCULATE THE NEXT AVAILABLE
LEG
if (!$canStopMetho d) {
$paddedUplinenu mber .= $this->uplinenumber . '11';
if (!$this->hasFoundNextAv ailRegNumber($p addedUplinenumb er)) {
$canStopMethod = 1;
return 0;
}
// KEEP INCREASING NEXT_TO_LAST DIGIT BY 1 UNTIL NO LONGER FOUND IN DB
AS REG #
while ($this->hasFoundNextAv ailRegNumber($p addedUplinenumb er))
$paddedUplinenu mber = $this->incrUplinenumb er($paddedUplin enumber);
$regNumber = $paddedUplinenu mber;
return 1;
}
}
// STRING METHOD
function incrUplinenumbe r($myUplinenumb er) {
$hexDigit = substr($myUplin enumber, strlen($myUplin enumber) - 2, 1); //
NEXT_TO_LAST DIGIT
$nextDecDigit = (int)hexdec($he xDigit) + 1;
return substr($myUplin enumber, 0, strlen($myUplin enumber) - 2) .
dechex($nextDec Digit) .
substr($myUplin enumber, strlen($myUplin enumber) - 1, 1);
}
// BOOLEAN METHOD
function hasFoundNextAva ilRegNumber($pa ddedUplinenumbe r) {
global $dbConn;
$sql = 'SELECT nnet_userid FROM nnet_usermetada ta ' .
'WHERE nnet_user_regis trationnumber = \'' . $paddedUplinenu mber .
'\' ';
$query = mysql_query($sq l, $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 getRegNumberDec Digits($myRegNu mber, $divider = '') {
for ($i = 0; $i < strlen($myRegNu mber); $i++)
$decRegNumber .= '' . hexdec(substr($ myRegNumber, $i, 1)) . $divider;
return $decRegNumber;
}
}
//---END OF
CLASS-----------------------------------------------------------------------
----
Phil 3 4529
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
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.u k> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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. In one
case, I might want a Library class with only Nations of with the
continent variable "Europe", and so I'll do something like
library.getContinent('Europe') which will return a Library() instance
with only European nations. Similarly, I...
|
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.
Thanks!
--
Erick Sasse
|
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 download a file no
problem. My issues come when I try to use the same class with the same
commands to access an FTP server on a UNIX box. I can connect and login
just fine, but after that all my commands come back "500 'PWD': command
not understood."....
|
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:
AClass() {}
};
|
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 ( yahooooo ) but i dont know why now I cant
get it to work the other way.
Vb 2003
Below are 2 examples. One Does not work and the other does.
| |
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
my Processes class. As far as i can tell i need to implement an
IEnuerator method to do this. But how ?
'Procs Class
Public Class Procs
Private _Id As Integer
|
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
{
public:
operator string(); // allow this class to be typecast into a string
operator char*(); // allow this class to be typecast into a char*
|
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 tells me if a variable has
changed, give me the original and current value, and whether the current
value and original value is/was null or not.
This one works fine but is recreating the same methods over and over for
each variable type.
...
|
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>
|
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), _netguid(netguid) {}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |