Jump to content

Display image if user reaches certain pecentage


cdoyle

Recommended Posts

Hi,

 

I've been working with a ezRPG game, and trying to modify it some to make it a little more unique.

 

One of the things I would like to do is on the users profile page, is display their win percentage (I have this part done), and also a little icon next to their percentage.  This icon that displays will depend on 2 things,  the total number of battles, and their win percentage.

 

So if they reach the min level for the next icon (for example 200 wins) they also need to keep their win percentage above 60% to get the new icon.  If they don't meet the 60% they get the 'easy target' icon.

 

So I'm trying to figure out how to do this.

 

I believe I'll need to make a new table in my DB, that has these fields 'the minimum battles needed for each', the 'icons', and 'description of the icon'.

 

but the part I can't figure out how to do is code the PHP to display the right icons. 

How would I write the query for that?

Link to comment
Share on other sites

 

SORRY REVAMPED LOL

 

Only a quick example for you......

 

<?php session_start();

$query="select * from table_name where deaths > '200' AND kills > '60' AND id='$id'";
$res=mysql_query($query) or die(mysql_error());

if(mysql_num_rows($res)==1){

$up="insert into table_name (id,battle,wins) values('$id','$battle','$wins','$pic')";
$ud=mysql_query($up)or die(mysql_error());
}

$query="select * from table_name";

$res=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_assoc($res)){

if(($row['battle'] >200)&&($row['wins']>60)){

$_SESSION['x']="<img src='pictures/".$row['pic']." ' />";

}else{

$_SESSION['x']="<img src='pictures/".$row['pic']." ' />";

}
}
//use $_SESSION['x'] on any page with session_start at the beging as shown
// to show the images.....

echo $_SESSION['x'];
?>

Link to comment
Share on other sites

updated

 

<?php session_start();

$query="select * from table_name where deaths > '200' AND kills > '60' AND id='$id'";
$res=mysql_query($query) or die(mysql_error());

if(mysql_num_rows($res)==1){

$id=mysql_real_escape_string($_POST['id']);
$battle=mysql_real_escape_string($_POST['battle']);
$wins=mysql_real_escape_string($_POST['wins']);
$pic=mysql_real_escape_string($_POST['pic']);

$up="insert into table_name (id,battle,wins) values('$id','$battle','$wins','$pic')";
$ud=mysql_query($up)or die(mysql_error());
}

$query="select * from table_name";

$res=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_assoc($res)){

if(($row['battle'] >200)&&($row['wins']>60)){

$_SESSION['x']="<img src='pictures/".$row['pic']." ' />";

}else{

$_SESSION['x']="<img src='pictures/".$row['pic']." ' />";

}
}
//use $_SESSION['x'] on any page with session_start() at the beging as shown
// to show the images.....

echo $_SESSION['x'];
?>

Link to comment
Share on other sites

Thank you for replying,

 

I'm looking at the code you posted, and I'm not sure if it's what I need or not. 

 

It's my fault, think I may not have explained very well what I'm trying to do.

 

I noticed in the query 200 is coded into it. I was just using that as example of one of the battle rank levels.  In my battle rank table, I want to be able to add as many different levels and icons as I can.  To give people something to work for.

 

Right now I only have 3 rows in the battle_rank table.

 

ID.....Min_Level.......Icon...........Description

1........0.............easy.gif......Easy Target

2........1.............Noob.gif......Noob

3........150..........hitman.gif.....hitman

 

so as the game progresses, I want to be able to add more, and have the query look at the total battle of a player, and check their win percentage and assign the appropriate gif.

 

So someone with 150 battles, with 60+% wins would get the hitman gif.

But someone with 150 battles, with a 49% win would get easy target.

 

Someone with 50 battles and 60% would get the noob gif.

Someone with 50 battle and 48% would get easy target.

 

I'm wondering if the PHP would even need to update the DB at all?  I've calculated the total wins already, I used that to get the %win.   

So I'm wondering if a query can be made that looks at the total wins, and then looks at the battle rank table,  and then if the % is high enough it displays the data from the appropriate row.

 

I've attached my home.php that shows where I listed the win%. 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.