MYSQL, PHP update table -


i scanned internet 2 days without result. try update empty cells in mysql table same value preceding cell:

+-------+      +-------+ |id |val|      |id |val| +-------+      +-------+ | 1 | 7 |      | 1 | 7 | | 2 |   |      | 2 | 7 | | 3 |   |      | 3 | 7 | | 4 | 4 |      | 4 | 4 | | 5 | 5 |after:| 5 | 5 | | 6 |   |      | 6 | 5 | | 7 |   |      | 7 | 5 | | 8 | 8 |      | 8 | 8 |  | 9 | 3 |      | 9 | 3 | |10 |   |      |10 | 3 | +-------+      +-------+ 

this solution, hope can you

$old_datas = [    [1,7],    [2,null],    [3,null],    [4,4],    [5,5],    [6,null],    [7,null]  ]; // old data table array : select * table 1 order id asc;    // set default pre value  $pre_val = 0;    foreach( $old_datas $old_data ){    if( !$old_data['val'] ){      // update table set val=$pre_val id=$old_data['id']    }else{      $pre_val = $old_data['val'];    }  }


Comments