I have populated an array using explode from a comma separated string variable. Now I need to access the data in the array.
I used:
print_r($values); // to see how the data was stored
//output
Array (
[0] => Array (
[0] => 1rv09is001
[1] => 07IS72 )
[1] => Array (
[0] => 1RV09IS064
[1] => 07IS72 )
)
I tried:
$a = count($values);
for($i;$i<$a;$i++){
$sql="UPDATE subject
SET attendance=attendance+1
WHERE usn=$values[$i][0] AND subCode=$values[$i][1]
";
echo "$sql";
mysql_query($sql);
}
It isn’t working.
Complex variable names (or arrays, for that matter) need to be enclosed in curly brackets when used inside of strings. Also, strings in MySQL need to be designated as such with quotes (single
'or double"):Also, you need to initialize
$iwith a value when used in a for loop.