Variable in an array

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
soap
Forum Newbie
Posts: 1
Joined: Wed Nov 24, 2010 9:45 am

Variable in an array

Post 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.
Last edited by Weirdan on Wed Nov 24, 2010 10:18 am, edited 1 time in total.
Reason: added syntax highlighting
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Variable in an array

Post by Weirdan »

Code: Select all

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