Echoing More Than One [RESOLVED]

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
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Echoing More Than One [RESOLVED]

Post by Epiales »

Okay, ran into an issue with my progress bar for my health.

I am wanting to put the percentage of health they have available instead of something like this: 50/100. I want it to show 50%.... But, I can't figure out how mix it together properly...

This is what I've tried:

Code: Select all

<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<img src='images/hpoints.png' width='$width' height='15' . $width . % . >";
?>
See how I have the progress bar echoed? But right after it I want it to echo the percentage, thus why I have the $width and %..... I need it on the same line/div, because if I try it anywhere else, it starts on a new line and I don't want that. There is plenty enough room after the progress bar to add this, so any help would be great. Thank you

EPI

***EDIT***

Have also tried it this way:

Code: Select all

echo "<img src='images/hpoints.png' width='$width' height='15' . '$width' . >";
Last edited by Epiales on Fri Sep 26, 2014 1:55 pm, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Echoing More Than One

Post by hallsofvallhalla »

I am not sure I understand completely what you mean but I think you need this

Code: Select all

<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<div style='float:left'><img src='images/hpoints.png' width='$width' height='15' . $width></div><div style='float:left'>%</div>";
?>
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Echoing More Than One

Post by Epiales »

hallsofvallhalla wrote:I am not sure I understand completely what you mean but I think you need this

Code: Select all

<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
echo "<div style='float:left'><img src='images/hpoints.png' width='$width' height='15' . $width></div><div style='float:left'>%</div>";
?>
It's showing the percent sign, but not the actual percentage left of the health.....it's also IN the progress bar, which not sure that would work?

Image
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Echoing More Than One

Post by Epiales »

I'm also searching the web to see if I can't round it off. So instead of 33.333333 percent, it would just be 33%.....
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Echoing More Than One

Post by Epiales »

Okay, I have figured out how to round by adding another step

Code: Select all

$width = ($row['hpoints'] / $row['maxhp']) * 100;
$rounded = round($width);
echo "<div style='float:left'><img src='images/hpoints.png' width='$width' height='15'></div>. $rounded <div style='float:right'>%</div>";
 
Just need to get it outside the bar grrr lol Thank you for helping
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Echoing More Than One

Post by Epiales »

Okay, so I can't figure it out, so I decided to just put the percentage either above or below the progress bar.... so that means I had to make it a longer bar to fit across...

Now I have this at 100% health:

Image

I didn't think it would make any difference by making the image longer... I thought the health would match it at 100% health? What did I do wrong?

Code: Select all

#hpointsback {
	position:absolute;
	margin:5px;
	top:450px;
	width:175px;
	height:15px;
	z-index:1;
}
#hpoints {
	position:absolute;
	margin:5px;
	top:450px;
	width:175px;
	height:15px;
	z-index:2;
	text-align:left;
}
The width of the divs are at 175, but the image of the barback is only at 150... so I figured it would go ahead and make the green stretch all the way to the end? It doesn't, so how can I do that? Thank you!

EPI
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Xaos
Posts: 946
Joined: Wed Jan 11, 2012 4:01 am

Re: Echoing More Than One

Post by Xaos »

Using divs you could just echo the percentage number and the % sign over the echo of the progress bar itself.
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Echoing More Than One

Post by Epiales »

Xaos wrote:Using divs you could just echo the percentage number and the % sign over the echo of the progress bar itself.
Yeah, I had it set that way earlier, but didn't like it. It's just not working as I wanted it. But now it won't stretch across to fill the entire progress bar. That's 100% up there and it only shows 3/4's health LOL. Still trying to figure it out.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 395
Joined: Thu Aug 08, 2013 8:57 am

Re: Echoing More Than One

Post by MikuzA »

What about just adding the variable with the percentage?

Code: Select all

<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
$rounded = round($width)
echo "<div style='float:left'><img src='images/hpoints.png' width='$width' height='15'></div><div style='float:left'>$rounded %</div>";
?>
-If you have it inside the <img> tag, that won't work.
-If you have it outside the <div> tags, this will misplace it somewhere unrelated to the divs.
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Echoing More Than One

Post by Epiales »

MikuzA wrote:What about just adding the variable with the percentage?

Code: Select all

<?php
$width = ($row['hpoints'] / $row['maxhp']) * 100;
$rounded = round($width)
echo "<div style='float:left'><img src='images/hpoints.png' width='$width' height='15'></div><div style='float:left'>$rounded %</div>";
?>
-If you have it inside the <img> tag, that won't work.
-If you have it outside the <div> tags, this will misplace it somewhere unrelated to the divs.
okay, that might work. I'll expleriment with it. maybe change the color to white so it's more noticable. But it doesn't work if I can't get the health to go all the way across the bar. When it's at 100%, it's only showing 75% full, so it's not spanning the green all the way across the red for whatever reason. I literally spent about 5 hours on that yesterday and I can't figure out why it's not spanning 100%. I thought it would. But I'll experiment with what you have. Thank you!
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Post Reply

Return to “Beginner Help and Support”