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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.