i have 2 functions, 1 is getting all numbers from a COLUMN and other function will transform numbers from COLUMN to NAME
The problem is, i have to Explode COLUMN because inside i have like that
SELECT NUMBER FROM ITEMS WHERE a_index=TEST
will result
NUMBERS Column 5000 -1 -1 -1 -1 -1 -1 -1 -1 15021 -1 -1 0 0 0 0 0 0 0 0 0 0 0 33
Names Translated Axe -1 -1 -1 -1 -1 -1 -1 -1 Sword -1 -1 0 0 0 0 0 0 0 0 0 0 0 Stone
How should be Axe Sword Stone
How to exclude 0 and -1 because SPACE must be separator
1.Column Function
function getNumber($id)
{
global $database;
$stmt = $database->runQueryPlayer("SELECT NUMBER FROM ITEMS WHERE a_index=?");
$stmt->bindParam(1, $id, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
if ($result)
var_dump(explode(" ", $result[0])); // Here i have to add translate function
else {
return '---';
} }
}
Result is that:
--- array(25) { [0]=> string(0) "" [1]=> string(2) "78" [2]=> string(2) "26" [3]=> string(2) "50" [4]=> string(2) "28" [5]=> string(2) "-1" [6]=> string(2) "30" [7]=> string(2) "32" [8]=> string(2) "-1" [9]=> string(2) "-1" [10]=> string(2) "-1" [11]=> string(2) "-1" [12]=> string(2) "-1" [13]=> string(1) "0" [14]=> string(1) "0" [15]=> string(1) "0" [16]=> string(1) "0" [17]=> string(1) "0" [18]=> string(1) "0" [19]=> string(1) "0" [20]=> string(1) "0" [21]=> string(1) "0" [22]=> string(1) "0" [23]=> string(1) "0" [24]=> string(1) "0" }
If i use function
return getName($result[0]);
ill get only first number, rest are not showing, if i use return getName(explode(" ", $result[0]));
nothing shows
2.Translate Function
function getName($id)
{
global $database;
$stmt = $database->runQueryPlayer('SELECT NAME FROM TRANSLATE
WHERE NUMBER = ?');
$stmt->bindParam(1, $id, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_COLUMN);
if($result)
return utf8_encode($result['0']);
else return '';
}