Page 1 of 1

Statistics = Raise?

Posted: Wed Apr 21, 2004 3:02 pm
by SilverMist
Hello all! I am looking for a script that, like when you pay your bills (on a virtual reality/SIM game) your general "Home Maintenance" stats would raise by one point. A database can be used, and code snippets would be lovely! Thanks in advance!

Posted: Wed Apr 21, 2004 3:09 pm
by Steveo31

Code: Select all

if($billspaid){
    $sql = "UPDATE tablename SET stats=stats+1 WHERE username = '$name' LIMIT 1";
    $query=mysql_query($sql) or die(mysql_error());
}
And somehow set a variable if the bills are paid.

Posted: Wed Apr 21, 2004 3:31 pm
by SilverMist
Okay, well I get that, but how will I make the little image stat bar thingy show up? Thanks!

Posted: Wed Apr 21, 2004 3:31 pm
by Weirdan
Steveo31 wrote: ... WHERE username = '$name' LIMIT 1 ...
Heh, one more paranoid here :lol:
No offence, I'm the one too =)

Posted: Wed Apr 21, 2004 3:39 pm
by John Cartwright
SilverMist wrote:Okay, well I get that, but how will I make the little image stat bar thingy show up? Thanks!
Can you explain?

Posted: Wed Apr 21, 2004 3:49 pm
by SilverMist
There will be a small red bar (picture) which shows your statistics. Right after the bar will be say 57% Maintained. The red bar would show 57% of 100. Is that a little bit clearer? Sorry for being so vague!

Posted: Wed Apr 21, 2004 3:52 pm
by kettle_drum
You can either have several pictures already made - called like 0.jpg, 5.jpg, 10.jpg etc and then call the one that is closest to the % you want to show.

The second option is to use GD to make an image on the fly that represents the % level.

Posted: Wed Apr 21, 2004 3:55 pm
by JAM
In the query, play around with SUM(), AVG() and other math functions to get the result ( in this case, 57% out of 100% ) you desire.
http://dev.mysql.com/doc/mysql/en/Mathe ... tions.html

To show the images, some ideas I can think of is to use <img src="foo.jpg" height="57%" /> or <img src="foo.jpg" height="57px" /> depending on flavour of choise or use the 57% value in any other way; <div>,<td>,<table> height/width.

Posted: Wed Apr 21, 2004 4:03 pm
by malcolmboston
SilverMist wrote:Okay, well I get that, but how will I make the little image stat bar thingy show up? Thanks!
you arw probably looking at GD functionality to be able to display image of that type (dynamic) GD is quite a complicated subject i sugest you read up0 on it

Posted: Wed Apr 21, 2004 4:40 pm
by jason
This is pretty simple.

First, you don't want GD to dynamically generate the static images. That's too much, and way overboard. Rather, let's say you want to use something like a 5 star image. If you have a rating of, let's say, 10, you have a half start, 20 = full star, 40 = 2 full stars, 60 = 3 full stars, etc.

So, now you name your star images 1.jpg, 2.jpg, 3.jpg, 4.jpg, etc. 1.jpg would be for people with at least 10 points, 2.jpg for at least 20 points, etc. 10.jpg for people with 100 points (and therefore, 5 stars). 0.jpg for people with less than 10 points, and therefore, 0 stars.

So anyways, after all this setup (which really isn't much), you can do something like this:

Code: Select all

if ( strlen($rating) == 3 ) {
	$img = '10';
} elseif ( strlen($rating) == 1 ) {
	$img = '0';
} else {
	$img = $rating{0};
}
echo '<img src="path/to/images'.$img.'.jpg">';
So you could use something like that. Pretty simple, I think.

Posted: Wed Apr 21, 2004 5:45 pm
by qads
just as a example, incase someone else wants to use it in a similar problem, but jason is right lol.

image.php

Code: Select all

<?php
header ("Content-type: image/png");
$l = $_GET['rate'] * 2 + 1;
if(isset($_GET['limit']) AND $l > $_GET['limit'])
{
$l = $_GET['limit'];
}
$img_handle = ImageCreate ($l, 12) or die ("Cannot Create image");
$back_color = ImageColorAllocate($img_handle, 200, 0, 0); 
if(isset($_GET['text']))
{
$text_len = strlen($_GET['text']) * 7;
$txt_color = ImageColorAllocate ($img_handle, 255, 255, 255);
imagestring($img_handle, 3, $l - $text_len, 0, $_GET['text'], $txt_color);
}
ImagePng ($img_handle); 
?>
how to use it

Code: Select all

&lt;img src="image.php?rate=50&amp;limit=300" /&gt;
"limit" is used to stop the image getting to big, in other words, this is the max width of the bar, even if the "rate" is 5000.

show text on bar as well?

Code: Select all

&lt;img src="image.php?rate=50&amp;limit=300&amp;text=50%" /&gt;
play around with it, change colors or whatever you need.