Hi, I have a somewhat complex form. My needs are unique. The form will be used on a School intranet. I used a table to lay it out as css was not cut for it. So it produces php variable like so:
$fname1, lname1, $eng1,$mat1,$ph1,$che1,$bio1,$geo1,$his1,$fn1
$fname2, lname2, $eng2,$mat2,$ph2,$che2,$bio2,$geo2,$his2,$fn2
$fname3, lname3, $eng3,$mat3,$ph3,$che3,$bio3,$geo3,$his3,$fn3
...
up to as many as 40 records depending on the number os students.
So the form is working well and i am able to insert data into mysql1 extension. The way I am doing it is time consuming because I have it as follows;
$query = "INSERT INTO pupils_records (date, fname1, lname2, exam_no1, eng, bio, che,...)
VALUES (NOW(),'$fname1', '$lname1', '$exam_no1', '$eng1','$bio1, '$che1', ...), (NOW(),'$fname2', '$lname2', '$exam_no2', '$eng2','$bio2, '$che2', ...), ... " ;
Now I want to use a loop so that I can pack those students records as arrays, each student record as one array, then pack the arrays in one array and then loop through the master array to build an insert query. I would use conditionals to make sure an array is only set of it has key values since the number of students will vary and the loop would use count to ascertain how many rows are available for the query.
Is this even possible? I have gone as far as capturing my variables into arrays, but I am having a hard time creating an insert using a loop. May be my theory is misguided, is there a better way to do this and still avoid repeating my self on the query?
I will appreciate your help, and thank you in advance.