Hi all,
I'm pretty new here but I do have "some" knowledge of sql and PhP, I'll start by telling you what I have and then ask what I need.
What I have:
I have a database which holds multiple tables, the one in question is called storage.sql
The table design for storage.sql is as follows:
-- ----------------------------
-- Table structure for `storage`
-- ----------------------------
DROP TABLE IF EXISTS `storage`;
CREATE TABLE `storage` (
`owner` int(11) NOT NULL DEFAULT '0',
`itemnum` int(11) NOT NULL DEFAULT '0',
`itemtype` int(11) NOT NULL DEFAULT '0',
`refine` int(11) NOT NULL DEFAULT '0',
`durability` int(11) NOT NULL DEFAULT '40',
`lifespan` int(11) NOT NULL DEFAULT '100',
`slotnum` int(11) NOT NULL DEFAULT '0',
`count` int(11) NOT NULL DEFAULT '1',
`stats` int(11) NOT NULL DEFAULT '0',
`socketed` int(11) NOT NULL DEFAULT '0',
`appraised` int(11) NOT NULL DEFAULT '0',
`gem` int(11) NOT NULL DEFAULT '0',
`sp_value` int(11) NOT NULL DEFAULT '0',
UNIQUE KEY `ow_slot` (`owner`,`slotnum`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
So, in the column 'itemnum' data is kept as a int, basically I run a game server and players put items into there storage then the database is updated to show the data, each item has it's own icon and each icon has its own icon number, I.e item number 1049 would be shown in the column 'itemnum' and has an icon number of 1049 either .jpg or .png
What I have done so far is query'd the sql file in PhP to show a players storage by there account i.d the code for which is below:
<?php // Database connection
$rs = mysql_connect($dbhost, $dbuser, $dbpasswd) or die('Could not establish database connection.');
mysql_select_db($dbname,$rs) or die(mysql_error());
if (!$rs)
{
die('Could not connect: ' . mysql_error());
}
print "Welcome:";
echo $_SESSION['account'];
$result = mysql_query("SELECT * FROM storage WHERE owner ='" . $_SESSION['account_id'] . "'"); // Selecting from storage
// Make box and name the fields in html
echo "<table border='1'>
<tr>
<th>Owner ID</th>
<th>Item#</th>
<th>Quantity</th>
</tr>";
// Fill box with data
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['owner'] . "</td>";
echo "<td>" . $row['itemnum'] . "</td>";
echo "<td>" . $row['count'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
As you can see from the above php file, the data is called from the sql file and shown to the user in a html table using the SELECT * FROM statement.
Now that's all fine and dandy, but, I want to show the user an image instead of raw data that is got from the sql query, I have an image in my httpdocs images folder called 1049.png and I want it to be displayed in the table to the user if he has that item in his storage..
Basically what I want is this:
->User logs into the site
->User opens his storage page
->Data is grabbed from the sql table
->For the 'itemnum' column I want that data to be converted in PhP ( without changing the table design ) to an image type and point to the image location in my httdocs
I have included some images below to show exactly what I mean in case It isn't clear above :)
Image showing the data displayed so far
http://img39.imageshack.us/img39/2215/66683684.jpg
Image showing where the data is kept
http://img502.imageshack.us/img502/3876/70264013.jpg
I have been baffling my head about this one for nearly a 3 months now and it's gotten to the point where I'm just about ready to pull my hair out...
Please, please, please can somebody help me.
Any and all suggestions are welcomed
Thanks in advance,
Mark