PDA

View Full Version : PHP Script -- Reading Profile Blob from MySQL


RazorJack
07-25-2003, 03:07 AM
For some reason, I could not login last night... only showed forever hacking listing. I loaded up my pico, and starting coding this:

<?php
$server = "localhost";
$username = "root";
$password = "xxxxxxx";
$dbname = "eq";

$link = mysql_pconnect($server,$username,$password);
mysql_select_db($dbname, $link);

$sql = "SELECT zonename, profile FROM character_";
$result = mysql_query($sql);

echo "<table border=\"0\" width=\"100%\">\n";
echo "<th>Name</th>\n";
echo "<th>Zone Name</th>\n";
echo "<th>Gender</th>\n";
echo "<th>Race</th>\n";
echo "<th>Level</th>\n";
echo "<th>Bind</th>\n";
while ($row = mysql_fetch_array($result)) {
$zonename = $row["zonename"];
$profile = $row["profile"];
$alt_adv = $row["alt_adv"];
$profileinfo = unpack("Lchecksum/a64firstname/a32lastname/Lgender/Lrace/Lclass/Lunknown/Llevel/Lzoneid/fbindx/fbindy/fbindz", $profile);

$firstname = $profileinfo["firstname"];
$lastname = $profileinfo["lastname"];
$gender = $profileinfo["gender"];
$race = $profileinfo["race"];
$class = $profileinfo["class"];
$level = $profileinfo["level"];
$zoneid = $profileinfo["zoneid"];
$bindx = $profileinfo["bindx"];
$bindy = $profileinfo["bindy"];
$bindz = $profileinfo["bindz"];
$bind = "$bindx, $bindy, $bindz";
$id++;


if ($gender == 0) {
$gender = "male";
} elseif ($gender == 1) {
$gender = "female";
}

echo "<tr>\n";
echo " <td align=center>$firstname $lastname</td>\n";
echo " <td align=center>$zonename ($zoneid)</td>\n";
echo " <td align=center>$gender</td>\n";
echo " <td align=center>$race</td>\n";
echo " <td align=center>$level</td>\n";
echo " <td align=center>$bind</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
?>

Hope its useful to atleast someone.

krich
07-25-2003, 10:54 AM
It is. I'm a PHP neophyte and these kinds of examples are easy to follow and easy to enhance based on the concepts included in this example.

Thanks.

krich

RazorJack
07-28-2003, 03:41 PM
NP. :)

I'll really expand on it once 0.5.0 is final and the database structure wont be changing for a few months.