Jump to content

Dynamic Array


bcart

Recommended Posts

Hi there

 

Can someone tell me why this isn't working?

 

$courses = array();

while($row_date = mysqli_fetch_array($r)) {

$courses[$row_date['ctID']][] = $row_date['ctID'];

}

 

foreach ($test as $key => $value) {

$insert_values .= "('{$_POST['course_date$key']}', '$id'), ";

}

 

$q_insert = "INSERT INTO induction_attendees (course, attendee)

VALUES ".substr($insert_values, 0, -2)."";

 

When I output the query it reads as follows

 

INSERT INTO induction_attendees (course, attendee) VALUES ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51'), ('', '51')

 

It's not picking up the $_POST['course_date$key'] part.

 

Can anyone help?

 

Cheers!

Link to comment
https://forums.phpfreaks.com/topic/181236-dynamic-array/
Share on other sites

If you put $var inside of single quites like '$var' then that literally mean '$var' it doesnt interpolate $var.

 

One way you could do this would be:

 

foreach ($test as $key => $value) {
  $key = 'course_date'.$key;
  $insert_values .= "(\'".$_POST[$key]."\', \'$id\'), ";
}

 

That should work but you should probably look into using bind variables where appropriate.

Link to comment
https://forums.phpfreaks.com/topic/181236-dynamic-array/#findComment-956200
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.