<?php
include("config.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// connect to the mysql server
$link = mysql_connect($db_host, $db_user, $db_pass)
or die ("nonono ".mysql_error());
// select the database
mysql_select_db($db_name)
or die ("nonono".mysql_error());
class data {
public function getchardata($charname,$opt){
$char = $this->myfetch($this->myquery("select decode(Column1,'decodekey') FROM TableName where Name = '$charname' "));
$blob = $this->strToHex($char[0]);
if($opt =='level')return hexdec(substr($blob,52,2));
if($opt =='coin')return hexdec(substr($blob,26,2).substr($blob,24,2).substr($blob,22,2).substr($blob,20,2));
if($opt =='pet')return hexdec(substr($blob,66,2).substr($blob,64,2).substr($blob,62,2).substr($blob,60,2));
if($opt =='credit')return hexdec(substr($blob,74,2).substr($blob,72,2).substr($blob,70,2).substr($blob,68,2));
if($opt =='exp')return hexdec(substr($blob,44,2).substr($blob,42,2).substr($blob,40,2).substr($blob,38,2).substr($blob,36,2));
}
}
?>
I have problem with this function: Using $this when not in object context. Anyone can help please? updated
The idea is to pass $this as parameter of your method/function.
So to call your function you will use something like : getchardata($charname,$opt,$this)
and inside your function you refer is as $_this
.
<?php
include("config.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// connect to the mysql server
$link = mysql_connect($db_host, $db_user, $db_pass)
or die ("nonono ".mysql_error());
// select the database
mysql_select_db($db_name)
or die ("nonono".mysql_error());
class data {
public function getchardata($charname,$opt,&$_this){
$char = $_this->myfetch($this->myquery("select decode(Column1,'decodekey') FROM TableName where Name = '$charname' "));
$blob = $_this->strToHex($char[0]);
if($opt =='level')return hexdec(substr($blob,52,2));
if($opt =='coin')return hexdec(substr($blob,26,2).substr($blob,24,2).substr($blob,22,2).substr($blob,20,2));
if($opt =='pet')return hexdec(substr($blob,66,2).substr($blob,64,2).substr($blob,62,2).substr($blob,60,2));
if($opt =='credit')return hexdec(substr($blob,74,2).substr($blob,72,2).substr($blob,70,2).substr($blob,68,2));
if($opt =='exp')return hexdec(substr($blob,44,2).substr($blob,42,2).substr($blob,40,2).substr($blob,38,2).substr($blob,36,2));
}
}
?>