cdoyle Posted March 2, 2008 Share Posted March 2, 2008 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? Quote Link to comment Share on other sites More sharing options...
cdoyle Posted March 2, 2008 Author Share Posted March 2, 2008 Not sure if it helps, but I have a players table that holds the win/losses. Fields are ID username kills deaths Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 2, 2008 Share Posted March 2, 2008 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']; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 2, 2008 Share Posted March 2, 2008 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']; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 2, 2008 Share Posted March 2, 2008 hope that helps a little bit and works good luck mate........ Quote Link to comment Share on other sites More sharing options...
cdoyle Posted March 2, 2008 Author Share Posted March 2, 2008 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%. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.