Statistics = Raise?
Moderator: General Moderators
- SilverMist
- Forum Commoner
- Posts: 65
- Joined: Tue Mar 02, 2004 2:06 pm
- Location: Canada
- Contact:
Statistics = Raise?
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!
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());
}- SilverMist
- Forum Commoner
- Posts: 65
- Joined: Tue Mar 02, 2004 2:06 pm
- Location: Canada
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- SilverMist
- Forum Commoner
- Posts: 65
- Joined: Tue Mar 02, 2004 2:06 pm
- Location: Canada
- Contact:
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
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.
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.
-
malcolmboston
- DevNet Resident
- Posts: 1826
- Joined: Tue Nov 18, 2003 1:09 pm
- Location: Middlesbrough, UK
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:
So you could use something like that. Pretty simple, I think.
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">';just as a example, incase someone else wants to use it in a similar problem, but jason is right lol.
image.php
how to use it
"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?
play around with it, change colors or whatever you need.
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);
?>Code: Select all
<img src="image.php?rate=50&limit=300" />show text on bar as well?
Code: Select all
<img src="image.php?rate=50&limit=300&text=50%" />