Jump to content

replace values less than a threshold


abdfahim

Recommended Posts

What I want is to replace all values from a result variable which are less than a certain threshold with that threshold. For example, say a sample php code is

$result=mysql_query("SELECT drop_rate from sTable WHERE field='DH001122'");

 

Now I want to replace values from $result which is less than 50, with 50. For example, if a value is 40, it will become 50, but if value is 60, it will remain 60. Can this be done in php?

Link to comment
Share on other sites

I'm not 100% sure what you're asking but if I'm right I would do this:

<?
$result=mysql_query("SELECT * from sTable WHERE field='DH001122'"); // noticed I changed the original query
while($res = mysql_fetch_array($result)){
if($res[drop_rate] < 50){
$drop_rate = 50;
}elseif($res[drop_rate] >= 50){
$drop_rate = $res[drop_rate];
}

$update = mysql_query("UPDATE sTable SET drop_rate='$drop_rate' WHERE field='DH001122'") or die(mysql_error());

}

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.