![]() |
Any Programmers Around Today?
I have a question and maybe one of you can help me.
What I want to do is find a customer record in a db. I need x to be equal to or greater than 1000 and y to be equal to or greater than 95% of x and if so - delete the customer record written out in a php code. Anyone help? |
Here is a tibit a code I used on one of my games
$x = 1000; $y = 950; $result = mysql_query ("SELECT * FROM $table WHERE x > '$x' && y > '$y' ORDER BY id DESC"); $nRows = mysql_num_rows($result); for ($i=0; $i< $nRows; $i++){ $row = mysql_fetch_array($result); $theid = $row['id']; $query124 = "DELETE FROM $table WHERE id= '$theid'"; mysql_query($query124) or die; } I am self taught and make no guarantees, but that worked for me |
oops, just saw where you wanted y to always be 95% of x so I revised it a bit
$x = 1000; $y = 950; $result = mysql_query ("SELECT * FROM $table WHERE x > '$x' && y > '$y' ORDER BY id DESC"); $nRows = mysql_num_rows($result); for ($i=0; $i< $nRows; $i++){ $row = mysql_fetch_array($result); $theid = $row['id']; $x2 = $row['x']; $y2 = $row['y']; if($y2 > ($x2 * .95)){ $query124 = "DELETE FROM $table WHERE id= '$theid'"; mysql_query($query124) or die; } } |
Hey, thanks!
|
Acck - need a little revision to this if anyone else care's to help out! (changed variables and added 1)
I need: x to be 500 OR GREATER y to be 95% of X OR GREATER and IF z is less than X - delete the record but if z is greater than X - disregard Y and keep the record Anyone help? |
homework help? eh?
|
PHP Code:
|
Quote:
|
I'll post something ... can you give actual field names and some sample values?
In fact you shouldn't even need PHP for this if you're trying to do what I think you are :P |
From what you wrote (where x, y, and z are field names):
DELETE FROM `table` WHERE x >= 500 AND y>=(x * 0.95) AND z < x; Might want to run a SELECT * FROM `table` WHERE x >= 500 AND y>=(x * 0.95) AND z < x; first to make sure you've got all the correct data in there... and I recommend backing up the table first too :P |
Fights Won: 100 Fights Lost: 543
Opponents Killed: 68 Deaths: 505 Jobs Completed: 6375 OK, this is dumb, but at the same time take a bit of thought so you don't delete an account that doesn't fall into the criteria that's intended. There's this online game where you can attack - be attacked or do jobs (or a mixture of both). If you do the jobs, you lose stats boosting points making you weaker than other opponents so you'll die more (deaths). When a weak opponent attacks a strong opponent and dies - the stronger gets the stats boost so we call those weak account "padders". Accounts whose only purpose is to "pad" stronger opponents stats. Those are the ones we want to find and delete. The stats shown above is a good example because it's primarily a job doer account - but is used to pad now and then as well. You can tell that because the fights lost and the deaths are pretty darn close (within 95%). To keep from eliminating it, you have to have a higher job than fight lost ratio so that it's kept. That's why I set the minimum fights lost at 1000 (above dog doesn't meet that criteria so it would be kept) But, that isn't a perfect solution either because what if the stats looked like this: Fights Won: 100 Fights Lost: 543 Opponents Killed: 68 Deaths: 505 Jobs Completed: 75 Now we'd know (because of the low job's completed number) that this account is used to pad with - but doesn't meet the 1000 minimum number set - so we'd be missing alot of accounts to delete). How would you go about scooping up all the padders without deleting an account that does the jobs? |
I have no idea if this will help - I couldn't fully understand what you need from reading your posts so it's a shot in the dark.
Code:
DELETE FROM `dogs` WHERE (`losses` >= 1000 AND ( ( `deaths` / `losses` ) * 100 ) > 90 ) OR ( ( ( `deaths` / `losses` ) * 100 ) > 90 AND `jobs` < `losses` ); |
Quote:
|
All times are GMT -7. The time now is 08:17 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123