Page 1 of 1

Health Progress Issue [RESOLVED]

Posted: Thu Sep 25, 2014 5:29 am
by Epiales
Hey all,

I've began working on my game again. Actually, just starting completely from scratch. Things have come back to me quickly, but I'm having an issue with the progress bar that shows the health of the player. I have the exact same as the older tutorials, and it works there, but doesn't work on my script. Below is my code.... anyone see anything wrong?

Code: Select all

<?php
$sql = "SELECT * FROM users WHERE id = '$_SESSION[userid]'";
$user_query2 = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query2);
$row = mysqli_fetch_array($user_query2, MYSQLI_ASSOC);
?>
<link rel="stylesheet" href="style/style.css">

<div id="hpointsback">
<?php
echo "<img src='images/hitpoints2.png'>";
?>
</div>
<div id="hpointsfront">
<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<img src='images/hitpoints1.png' width='$width' height='15' >";
?>
</div>

Code: Select all

#hpointsfront {
	position:absolute;
	left:1500px;
	top:300px;
	width:100px;
	height:15px;
	z-index:1;
}
#hpointsback {
	position:absolute;
	left:1500px;
	top:300px;
	width:100px;
	height:15px;
	z-index:2;
	text-align:left;
}
So you know, this is all it shows in my Google Chrome:
http://gyazo.com/4b0f2cdc6e10c35043a8171cbe57b63a

This is what it shows in Firefox:
http://gyazo.com/44e74f9314bb96f650c12aad3c266222

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 8:34 am
by MikuzA
The code looks fine so I'm thinking there might be some issues with the data.

Can you
echo $row['hpoints'];
echo $row['maxhp'];
echo $width;

at the end?

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 8:52 am
by Epiales
MikuzA wrote:The code looks fine so I'm thinking there might be some issues with the data.

Can you
echo $row['hpoints'];
echo $row['maxhp'];
echo $width;

at the end?
I get 10, 25, and 40....

10 is the hitpoints currently
25 is the max hitpoints

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 9:44 am
by Epiales
Okay, I think my problem is that the Green bar that goes up and down with the users Hitpoints is BEHIND the red bar. It's not letting me switch it for whatever reason. grrr :oops:

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 10:17 am
by MikuzA
Ah, ok I see what you are trying..
What about setting the div-background as the 'back' and just displaying the image aligned left on it?

So that the <div id="hpointsback"><img></div>
And set the div width/height to the exactly same as the image, would that do any good? :-)

Also, I see it kinda wierd it's trying to divide with zero in Firefox :P That's why I thought the data was off..

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 10:56 am
by Epiales
MikuzA wrote:Ah, ok I see what you are trying..
What about setting the div-background as the 'back' and just displaying the image aligned left on it?

So that the <div id="hpointsback"><img></div>
And set the div width/height to the exactly same as the image, would that do any good? :-)

Also, I see it kinda wierd it's trying to divide with zero in Firefox :P That's why I thought the data was off..
Yeah, I think the url isn't updating quickly enough lol.... okay, here is what I have and no reason it should be off

Code: Select all

#hpointsback {
	position:absolute;
	margin:5px;
	top:300px;
	width:100px;
	height:15px;
	z-index:1;
}
#hpoints {
	position:absolute;
	margin:5px;
	top:300px;
	width:100px;
	height:15px;
	z-index:2;
	text-align:left;
}
Notice: They should be RIGHT ON TOP OF ONE ANOTHER based on the above css....

here's the php

Code: Select all

<div id= "hpointsback">
<?php
echo "<img src='images/barback.png'>";
?>
</div>
<div id= "hpoints">
<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<img src='images/hpoints.png' width='$width' height='15' >";
?>
</div>
What it looks like:

Image

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 11:12 am
by Epiales
Okay, so it finally udpates lol...

Image

That sure doesn't look like 50/50 to me????

Re: Health Progress Issue

Posted: Thu Sep 25, 2014 11:29 am
by Epiales
YAY YIPPEEEEEEEEEEEEEEE!!!

:roll: :roll: :roll: After 50 hours it finally works right LMAO! So frustrating...forgot how frustrating coding was lmao! Thanks for u're help m8 :)