I have an array $columns which contains the chosen values from the user. The user values is supposed to be saved in a database table so that the next time, the user wont be given points for the values that he or she chose the last time. Messy? A bit of code plz? ok:
$columns= isset($_POST['column']) ? $_POST['column'] : array();
print_r($columns);
So all columns that is chosen gets the value 1, and the other ones have value 0. This gives me:
Array ( [0] => 1 [1] => 1 [2] => 1 [4] => 1 [7] => 1 )
I have a database table with 8 different columns namned column1,column2,columnN.... I want to compare the database table to my array. To know which column to update. Now im thinking:
while($row = mysql_fetch_array( $result )) {
if($row['column'.$checks]!=1){
//update table with values
}
}
Should I compare my array to $row? or intersection? how can I get the values needed from my array?
Why not merge all those tables into one.
id | column_id | check
Which will make updating values a lot easier
foreach ($columns as $column_id => $value) {
// UPDATE `table` SET check = {$value} WHERE column_id = {$column_id};
}