I'm developing an attendance management program, accustomed to keep up with the absence record of the student. Customers of the software will have to enter various dates, up-to-date occasionally month: for example, a listing of dates which students was absent for your particular month could be joined, and my program must then store them right into a database with every date added like a new row within the appropriate table.
I've the dates saved using arrays internally, how might I transfer these in to the database? How must i proceed?
You haven't pointed out the database system getting used, so my reply is general in character. The typical method of doing this really is to operate multiple place claims one to another:
INSERT INTO Table1 (FirstColumn, SecondColumn) VALUES ('a', 'b'); INSERT INTO Table1 (FirstColumn, SecondColumn) VALUES ('c', 'd'); INSERT INTO Table1 (FirstColumn, SecondColumn) VALUES ('e', 'f'); GO
The secret method of doing this is by using the UNION ALL statement:
INSERT INTO Table1 (FirstColumn, SecondColumn) SELECT 'a', 'b' UNION ALL SELECT 'c', 'd' UNION ALL SELECT 'e', 'f' GO
Versions of SQL Server just before 2008 support only these techniques. But SQL 2008 and MySQL 3.22 and above offer the Row construction method too:
INSERT INTO Table1 (FirstColumn, SecondColumn) VALUES ('a', 'b'), VALUES ('c', 'd'), VALUES ('e', 'f') GO
You can now use any of these techniques to iterate using your array and add individual attendance rows towards the database.
foreach($arrayName as $arrayValue)
$myArray = array('apple','orange','grape') foreach($myArray as $arrayFruit) Place INTO `Fruits` (`FruitName`) VALUES ('" . $arrayFruit . "')" mysql_query($query, $connection)
does which makes sense / fit that which you were thinking?
Would you like to keep dates seperately so that you can juggle together, query them, etc.? Or do you want to keep array out of the box?
If you wish to keep dates individually you might want to produce a table by having an FK to students, a column for date along with a column for that character from the date, like absence, late, ...
You would then indeed keep single dates into that table. Should you must, by iterating but when you are able to and among Cerbrus' solutions!. It's not suggested to possess db-queries within loops.
If you need to simply store that array somewhere, you are able to serialize it and keep serialized string inside a text or varchar column.
Iterate within the array and execute place SQL for every date.
What language and which kind of database are you currently using? Is an internet application? A desktop application? We can not assist you to without more details.
Based on your circumstances, any of these solutions perform. Or you might even load all the attendance records at the same time like a CSV or XML document. Possibly a bit more research from you can help you request a far more helpful question?