Posts: 79
Threads: 8
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Oct 2011
Reputation:
0
Hello! I want to programm a "tool" to see in the webpanel of my website the Inventorys of my chars
For example my char had the unique ID: 981, what i must du, to see the full Inventory? or the Money?
How to parse the images with the icons of armor etc? (Solved)
THX for Help
//EDIT:
To Parse Picture:
Get ROW: (e.g: 8)
Get Collum: (e.g: 9)
Get FileID (ItemBtn0.png)
(ItemID: 20)
ID20 { display: inline-block; width: 32px; height: 32px; background: url(ItemBtn0.png) no-repeat 0 0; }
ID20 { background-position: -288px -256px; }
Short script to get the Icon:
// CONFIG
$SIZE = "32"; // 32x32 standart
// CONFIG --> ItemID = FileID,COL,ROW
$ID['19'] = "0,0,0";
$ID['20'] = "0,8,9";
$IDENT = $_GET['id'];
if(!isset($ID[$IDENT])) {
echo "Error!";
exit;
} else {
echo "<style>";
$R = mb_split(",",$ID[$IDENT]);
$ITE = $R[0];
$COL = $SIZE*$R[1];
$ROW = $SIZE*$R[2];
echo '
ID'.$IDENT.' { display: inline-block; width: 32px; height: 32px; line-height: 32px; background: url(ItemBtn'.$ITE.'.png) no-repeat 0 0; }
ID'.$IDENT.' { text-decoration: none; background-position: -'.$ROW.'px -'.$COL.'px; }
';
echo "</style>";
echo "<ID".$IDENT."></ID".$IDENT.">";
}
Posts: 313
Threads: 20
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Jul 2011
Reputation:
0
You would need to read about Mysql query's and how to use it with php(read about PDO, or Mysqli):
Get character ID(don't forget to sanitize your inputs):
$charName = "MySorc";
query = "SELECT a_index FROM t_characters WHERE a_name ='".$charName."';";
Afteryou got the Id you can simply query the t_invent0-9 from
charID = row["a_index"];
for( $i = 0; $i < 10; $i++){
query = "SELECT * FROM t_inven0".$i." WHERE a_char_idx=".charID.";";
//Execte the query and get the rowand parse it using a_item_idx0,
//a_item_idx1, a_item_idx2, a_item_idx3, a_item_idx4 or any other tables
}
First thing you will need to create an entity class of the table in the database, thatwill hold the table information.
t_invent.class.php
<?php
class t_invent{
//make it private and add get/set methods
public $a_char_idx;
public $a_tab_idx ;
public $a_row_idx;
//....
};
?>
And the Php File that loads everything
<?php
//include your php files
require_once 'Database/t_invent.class.php';
//your program
$inventory = array();
//for every inventory 0-9
for($i = 0 ; $i < 10; $i++ ){
//Create query
// execute query
$inventory[$i] = new t_invent();
$inventory[$i]->a_char_idx = $row["a_char_idx"];
$inventory[$i]->a_tab_idx = $row["a_tab_idx"];
$inventory[$i]->a_row_idx = $row["a_row_idx"];
//...
}
//...
//later in the program later in the program you can access the inventories using $inventory[$num]->field
?>
For simple querys and user input/output I suggest you try to use AJAX + PHP, since its much simpler to make an HTTP request then loading the full page, just to make a simple query.
Posts: 313
Threads: 20
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Jul 2011
Reputation:
0
Here is a nice script to help you not waste time creating classes for every, table, just nun it and it will create your php class files for you to use in your scripts(saves a lot of time).
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "ghst";
$dbname = "newproject_db";
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
echo "Checking directory: Database/".$dbname."<br>";
//directories creating the;
if(!is_dir("Database")){
mkdir("Database");
}
if(!is_dir("Database/".$dbname)){
mkdir("Database/".$dbname);
}
//create a query and execute
$query = "Show Tables";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$info = $result->fetch_fields();
$table =array();
//for every row (table it founds)
for($i = 0;$row = $result->fetch_assoc(); $i++) {
$table[$i] = $row[$info[0]->name];
}
//open a file and write the data inot the file
$numTable = count($table);
echo " Tables foud:".$numTable."<br>";
for($i = 0; $i < $numTable; $i++){
echo "Writing: ".$table[$i]." to the file<br>";
$file = fopen("Database/".$dbname."/".$table[$i].".class.php", "w");
$fData = "<?php\n class ".$table[$i]."{\r\n";
$query = "describe ".$table[$i].";";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$info = $result->fetch_fields();
//for every field in the table write the field name
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$field = $row[$info[0]->name];
$fData.= "\tpublic $".$field.";\r\n";
}
}
//finish the string and close the file
$fData .="};\r\n?>";
fwrite($file, $fData);
fclose($file);
}
//close mysql connection
mysqli_close($mysqli);
?>
Posts: 768
Threads: 40
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: May 2011
Reputation:
0
And u can use this to display the icon.
Save it as icon.php.
then use it as that is id:row:col
<?php
$str = explode(':', $_GET['i']);
$id = $str[0];
$row = $str[1];
$col = $str[2];
// Create image instances
$src = imagecreatefrompng('data/icon/ItemBtn'.$id.'.png');
$dest = imagecreatetruecolor(32, 32);
$row_start = $row * 32;
$row_end = $row_start + 32;
$col_start = $col * 32;
$col_end = $col_start + 32;
// Copy
imagecopy($dest, $src, 0, 0, $col_start, $row_start, $col_end, $row_end);
// Output and free from memory
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>
And this is what i use to display the inventory on my adminpanel
<?php
class Character
{
var $invenRows;
function GetInventory($cid)
{
global $db, $s;
$l = substr($cid, -1);
$query = sprintf
("
SELECT
*
FROM
%s.t_inven0%d
WHERE
a_char_idx = :cid
", $s->db,
$l );
$dbh = $db->prepare( $query );
$dbh->execute( array( ':cid' => $cid ) );
$count = $dbh->rowCount();
if( $count > 0 )
{
$i=0;
$result = $dbh->fetchAll();
foreach( $result as $row )
{
for($j=0; $j<5; $j++)
{
if( $row['a_item_idx' . $j] != '-1' )
{
$this->invenRows[$i]['id'] = $row['a_item_idx' . $j];
$this->invenRows[$i]['plus'] = $row['a_plus' . $j];
$this->invenRows[$i]['amount'] = $row['a_count' . $j];
$this->invenRows[$i]['flag'] = $row['a_flag' . $j];
$this->invenRows[$i]['opt0'] = $row['a_item' . $j . '_option0'];
$this->invenRows[$i]['opt1'] = $row['a_item' . $j . '_option1'];
$this->invenRows[$i]['opt2'] = $row['a_item' . $j . '_option2'];
$this->invenRows[$i]['opt3'] = $row['a_item' . $j . '_option3'];
$this->invenRows[$i]['opt4'] = $row['a_item' . $j . '_option4'];
$this->invenRows[$i]['row'] = $row['a_row_idx'];
$this->invenRows[$i]['col'] = $j;
$i++;
}
}
}
}
return $count;
}
}
?>
this gives u the array Character::invenRows[];
Posts: 768
Threads: 40
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: May 2011
Reputation:
0
hmmm stupid code parsing...
Posts: 79
Threads: 8
Thanks Received:
0 in 0 posts
Thanks Given: 0
Joined: Oct 2011
Reputation:
0
<?php
function GetGet($STRING) {
$return = $_GET[$STRING];
return $return;
}
$IDENT2 = @GetGet('char');
function GetItem($IDENT1) {
// CONFIG
$SIZE = "32"; // 32x32 standart
mysql_connect("127.0.0.1","root","") or die(mysql_error());
mysql_select_db('newproject_data');
$A = mysql_query("SELECT * FROM t_item WHERE a_index = ('".$IDENT1."');");
$RES = mysql_fetch_array($A);
if(mysql_num_rows($A) == "0") {
$ID = "15,13,0";
$IDENT1 = "1";
} else {
$ID = $RES['a_texture_id'].",".$RES['a_texture_row'].",".$RES['a_texture_col'];
}
echo "<style>";
$R = mb_split(",",$ID);
$ITE = $R[0];
$COL = $SIZE*$R[1];
$ROW = $SIZE*$R[2];
echo '
ID'.$IDENT1.' { display: inline-block; width: 32px; height: 32px; line-height: 32px; background: url(ItemBtn'.$ITE.'.png) no-repeat 0 0; }
ID'.$IDENT1.' { text-decoration: none; background-position: -'.$ROW.'px -'.$COL.'px; }
ID'.$IDENT1.':hover {
';
echo "</style>";
if($IDENT1 == "-1") {} else {
echo "<ID".$IDENT1."></ID".$IDENT1.">";
}
}
if(isset($_GET['char'])) {
$L = strlen($IDENT2);
$A = $L-1;
$ID = str_split($IDENT2,$A);
mysql_connect("127.0.0.1","root","") or die(mysql_error());
mysql_select_db('newproject_db');
$SQL = "SELECT * FROM t_inven0".$ID[1]." WHERE a_char_idx = ('".$IDENT2."');";
$res = mysql_query($SQL);
$I = "0";
while ($A = mysql_fetch_array($res)) {
if($I == "0") {echo "1 Kategorie<br>";}
if($I == "5") {echo "2 Kategorie<br>";}
if($I == "10") {echo "3 Kategorie<br>";}
if($I == "15") {echo "4 Kategorie<br>";}
if($I == "20") {} else {
if($A['a_tab_idx'] == "0") {
if($A['a_row_idx'] == $I) {
GetItem($A['a_item_idx0']);GetItem($A['a_item_idx1']);GetItem($A['a_item_idx2']);
GetItem($A['a_item_idx3']);GetItem($A['a_item_idx4']);
echo "<br>";
}
}
}
$I = $I+1;
}
echo $SQL;
}
I Only need my Char ID Working Fine