I have a set of information in which I will blow it up with id, code and number.
list ($id,$code,$num) = explode("~",$data);
I need to upgrade it to MySql based on a unique code with a minimum num value
Suppose my first 3 queries look like
id = 9267399 code = 5D:148 num = 64 id = 9267398 code = 5D:186 num = 71 id = 9267397 code = 5D:122 num = 93
Then my 4th, 5th requests have a duplicate code 5D:148 with different identifiers and numbers.
id = 9267402 code = 5D:148 num = 22 id = 9267563 code = 5D:148 num = 5
Now I need to find min(num) for the duplicate code and update this entry back to mysql. My queries should look like
$sql = "UPDATE table SET id = '9267398', num = '71' WHERE code = '5D:186' "; $sql = "UPDATE table SET id = '9267397', num = '93' WHERE code = '5D:122' "; $sql = "UPDATE table SET id = '9267563', num = '5' WHERE code = '5D:148' ";
here 5D:148 has 3 queries in which min(num) is 5.
I tried to find duplicate code
$temp = array(); foreach ($code as $c) { isset($temp[$c]) or $temp[$c] = 0; $temp[$c] ++; } var_dump($temp);
It gives me
array(3) {["5D:148"]=> int(3) ["5D:186"]=> int(1) ["5D:122"]=> int(1)}
I'm stuck here how to find min(num) and run my update request on it