Item images help

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
deluxxmanx
Posts: 88
Joined: Thu Nov 26, 2009 10:22 pm

Item images help

Post by deluxxmanx »

So, basically I want every item in my game to have an image.
I'm not the best at coding and now I ran into a problem. I worked for 2 weeks to make it for the houses/properties. When buying a property you can view it's picture. So basically I'm wanting to convert that script and use it on items as well, but I ran out of ideas how to do it. Basically how it works is that you make a new folder, and add there pics in PNG format with the house's name, the image area searches for that pic in that folder by the name of the house your viewing and it loads it.

It's really easy to use and add new images to my game, that's why I want to use this method on my items as well but I can't figure out how to convert it. I know that I should do it myself but been trying it for ages and can't make it, so what I'm asking is please I'm sure it's not hard for an advanced coder could you please convert it for me aka rewrite it? It's not really long in lines too, my guess would take ya like 10-15mins. I'd really appreciate it, thank you a lot!!! :)

p.s. I don't mind about the layout at ALL just need the page to show that image anywhere, thanks.

Estate.php ( house/property buying/viewing page ) the one that needs to be converted

Code: Select all

<?php

include_once('globals.php');

	echo '<h2><font color=darkred>Estate Agent</font color></h2><font color=white>';
	
if(!$_GET)
	{
		return index();
	}
	
switch($_GET['p'])
	{
		case 'buy' : buy(); break;
		case 'viewHouse' : viewHouse(); break;
		default: index();
	}

function index()
	{
		global $db, $ir, $h;
		
		$house = $db->fetch_row( $db->query("SELECT `hNAME` FROM `houses` WHERE `hWILL`=". $ir['maxwill'] ." ") );
		echo '<strong><font color=yellow>Your current Property:</font color></strong> <font color=white>', $house["hNAME"] ,' </font color>
					<br />
			  <i><font color=white>Welcome to the estate agent, <font color=red>', $ir["username"] ,'</font color>. Here you can view the properties avaliable and purchase them.</font color></i>
			  		<br /><br />';
			  		
		$get = $db->query("SELECT `hNAME`,`hID` FROM `houses` ORDER BY `hWILL`,`hNAME` ASC");
		while($r = $db->fetch_row($get))
			{
				echo  "<font color=red><i>". $r['hNAME'] ."</i> » <a href='?p=viewHouse&id=".$r['hID']."'>View the house</a><br />";
			}
		exit( $h->endpage() );
	}
	
function viewHouse()
	{
		global $db, $ir, $h;
		$_GET['id'] = (isset($_GET['id']) & abs( is_numeric($_GET['id'])) ) ? $_GET['id'] : FALSE;
		if($_GET['id'] == FALSE OR $_GET['id'] <= 0)
			{
				echo "We aren't selling this property at the moment!
						<br />
					  » <a href='?p=index'>Back to Estate Agent</a>";
				exit( $h->endpage() );
			}
		$exist = $db->query("SELECT `hNAME`,`hWILL`,`hPRICE` FROM `houses` WHERE `hID`=". $_GET['id'] ." ");
		if($db->num_rows( $exist ) == 0)
			{
				echo "We aren't selling this property at the moment!
						<br />
					  » <a href='?p=index'>Back to Estate Agent</a>";
				exit( $h->endpage() );
			}
		$r = $db->fetch_row($exist);
		echo "<h4> » <strong>Viewing:</strong> {$r['hNAME']} </h4>
					<br />
		<div style='width: 500px; padding: 5px; background: #D4D4D4; border: 1px solid #000000; text-align: center;'>
				<img src='housepic/{$r['hNAME']}.png' height='200px' width='300px' style='border: 1px solid #D0D0D0;'>
		</div>
			<br />";
			
		$color = ($ir['money'] >= $r['hPRICE']) ? "green" : "red";
		
		echo "<font size='34pt' color='".$color."'>$".number_format($r['hPRICE'])."</font>	
				<br />
				<br />
		<strong>House Statistics</strong>
			<br />
		Amount owned: ". $q = $db->num_rows( $db->query("SELECT `userid` FROM `users` WHERE `maxwill`={$r['hWILL']}") ) ."	
			<br />
		Will Increase: 	". $will = ($r['hWILL'] / 100) * $ir['maxwill'] ."%";
		
		if($color == "green" AND $ir['maxwill'] < $r['hWILL'])
			{
				echo "<br /><br /><font size='34pt'>» <a href='?p=buy&id=".$_GET['id']."'>Purchase</a>";
			}
		exit( $h->endpage() );
	}
	
function buy()
	{
		global $h, $db, $userid, $ir;
		$_GET['id'] = (isset($_GET['id']) & abs( is_numeric($_GET['id'])) ) ? $_GET['id'] : FALSE;
		if($_GET['id'] == FALSE OR $_GET['id'] <= 0)
			{
				echo "We aren't selling this property at the moment!
						<br />
					  » <a href='?p=index'>Back to Estate Agent</a>";
				exit( $h->endpage() );
			}
		$exist = $db->query("SELECT `hNAME`,`hPRICE`,`hWILL` FROM `houses` WHERE `hID`=". $_GET['id'] ." ");
		if($db->num_rows( $exist ) == 0)
			{
				echo "We aren't selling this property at the moment!
						<br />
					  » <a href='?p=index'>Back to Estate Agent</a>";
				exit( $h->endpage() );
			}
		$r = $db->fetch_row($exist);
		if($ir['money'] < $r['hPRICE'])
			{
				echo "You don't have enough money at the moment!
						<br />
					  » <a href='?p=index'>Back to Estate Agent</a>";
				exit( $h->endpage() );
			}
		if($ir['maxwill'] > $r['hWILL'])
			{
				echo "You don't want to get a smaller property do you?!
						<br />
					  » <a href='?p=index'>Back to Estate Agent</a>";
				exit( $h->endpage() );
			}				
		echo "Congratulations, you have just purchased a {$r['hNAME']} for $".number_format($r['hPRICE'])."!
						<br /><br>
					  » <a href='index.php'>Back Home</a>";
			  $db->query("UPDATE `users` SET `money`=`money`-{$r['hPRICE']},`maxwill`={$r['hWILL']} WHERE `userid`=$userid");
		exit($h->endpage());
	}
?>
And here is my current item viewing page, which I need to have the functions of the estate script so that I could add item pics using the same system.

iteminfo.php

Code: Select all

<?php
include "globals.php";
//look up item
$_GET['ID'] = abs((int) $_GET['ID']);
$itmid=$_GET['ID'];
if(!$itmid)
{
print "Invalid item ID";
}
else
{
$q=$db->query("SELECT i.*,it.* FROM items i LEFT JOIN itemtypes it ON i.itmtype=itmtypeid WHERE i.itmid=$itmid LIMIT 1");
if (!$db->num_rows($q))
{
print "Invalid item ID";
}
else
{
$id=$db->fetch_row($q);
///Item Image SQL
print "<b><h2>Information on the <u><font color=red>{$id['itmname']}</font color></u></b></h2><br>";
///Item Image:
///echo "<img src='itempics/{$r['itmname']}' height='160px' width='100px' style='border: 1px solid #000000;'>
echo "<br>The <b>{$id['itmname']}</b> is a/an {$id['itmtypename']} Item - <b>{$id['itmdesc']}</b>Item Info Item Buy Price Item Sell Price ";
if($id['itmbuyprice'])
{
print money_formatter($id['itmbuyprice']);
}
else
{
print "N/A";
}
print "";
if($id['itmsellprice'])
{
print money_formatter($id['itmsellprice']);
}
else
{
print "N/A";
}
}
}
$h->endpage();
?>
                                  
other info:
database name: legendaryassassins
table name: items

"items" structure
Image
Image
I am a PS CS4 artist. Signature above made by me.
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Item images help

Post by Xaleph »

Best thing you can do is create a new table where you store all the paths to your images. In your items/houses/property/character/ tables, you add a new field where you store the ID of the row with the path to that image. This way, you can query the path file and thus return that path along with your data. Once it hits the browser, the path will find its way to the picture and tadaa.
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Item images help

Post by Torniquet »

Using your code,

the line which contains this line...

Code: Select all

///echo "<img src='itempics/{$r['itmname']}' height='160px' width='100px' style='border: 1px solid #000000;'> 
your missing the file extension from the src.

that will work fine if your images are the same as their names. so put .jpg/.png or what ever format they are on the end of the src and you should be good to go.

Code: Select all

echo "<img src='/itempics/{$r['itemname']}.png' height='160px' width='100px' style='border: 1px solid #000000;' />" 
New Site Coming Soon! Stay tuned :D
deluxxmanx
Posts: 88
Joined: Thu Nov 26, 2009 10:22 pm

Re: Item images help

Post by deluxxmanx »

I thought so too Tor, I've tried that but it didn't help. :?
Image
I am a PS CS4 artist. Signature above made by me.
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: Item images help

Post by Torniquet »

ok, try escaping the echo before playing in the item name. Also you are assigning the row information to $id and not $r (i didnt notice this at 1st)

So you would have

Code: Select all

echo "<img src='/itempics/" . $id['itemname'] . ".png' height='160px' width='100px' style='border: 1px solid #000000;' />"  
if its not that, then it has something to do with your file structure and file names. There is no reason that shouldnt work :s
New Site Coming Soon! Stay tuned :D
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Item images help

Post by Jackolantern »

Have you been looking at the HTML generated by your script? A lot of times for complex img tag scripts that is a great help to see where it is going wrong. If that doesn't immediately show the problem, copy the created img tag, and paste it into a blank static HTML page. That will allow you to more easily play with the code to get it working, and then you can translate those changes back into the PHP script.
The indelible lord of tl;dr
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: Item images help

Post by Perry »

This is just something you might try. How do you have your folders set up? If you put this like this
"/itempics/" . $id['itemname'] . ".png"
Then it will look for a folder called itempics at the top of your directory. If you have itempics inside the folder with all your scripts you should remove the "/" like this "itempics/" . $id['itemname'] . ".png" If you have it one folder up you should try "../itempics/" . $id['itemname'] . ".png"

Don't know if you had tried that or not. I was just glancing through and noticed that. Hope it helps.
deluxxmanx
Posts: 88
Joined: Thu Nov 26, 2009 10:22 pm

Re: Item images help

Post by deluxxmanx »

Thanks for all the replies guys, I'll try it out and will reply here if it works or not. :)

And @ last post - the itempics folder is with all the scripts in the main directory. :)
Image
I am a PS CS4 artist. Signature above made by me.
deluxxmanx
Posts: 88
Joined: Thu Nov 26, 2009 10:22 pm

Re: Item images help

Post by deluxxmanx »

I tried it torniquet and it didn't help. Funny part is, if let's say instead of the $r['itmname'] I put in the exact name of the image ( ex: Knife.png ) it shows the image just fine.

My guess would be maybe the script doesn't know the command and there should be stated where to find the info somewhere at start or something like that, I'm not sure, but my guess is that the script isn't somehow maybe familiar with the itmname thingy. Maybe like there is at start of a script 'fetch row' and similar things maybe that's what it needs? I'm really puzzled and this is the last bug I have before I can air a BETA of the game. :)
Image
I am a PS CS4 artist. Signature above made by me.
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: Item images help

Post by Perry »

Ok. Just making sure. :D
Post Reply

Return to “Beginner Help and Support”