Page 1 of 1

Variable in an array

Posted: Wed Nov 24, 2010 9:52 am
by soap
Hi,

I am a total newbie with php and mysql and I have a problem with how to put a variable in an array. What I'm trying to do is getting $data[$i] to work. Here's the snippet of code I have here that is not working. I know it is bad style but I'm in a hurry and just want to know how to get $data[$i] working.

Code: Select all

for ($i = 0; $i < 31; $i += 1){

$sql_insert = "INSERT INTO med_log (`user_id`, `date`, `med1`,`dose1`, `transfusion`)
VALUES ('$_SESSION[user_id]', '2010-11-01' , '$data[med1_{$i}]', '$daydose1[{$i}]', '$data[transfusion_{$i}]')";
mysql_query($sql_insert) or die(mysql_error());

}
Thanks so much in advance.

Re: Variable in an array

Posted: Wed Nov 24, 2010 10:20 am
by Weirdan

Code: Select all

"...{$data["med1_{$i}"]}..."