Simba Simba - 8 days ago 6
PHP Question

How to insert a String delimited by special chars into table

I'd like to do

INSERT
to a table. This table is a simple table.

student_id subject_id student_name student_report
S001 M01 Albert A+
S001 M02 Albert A
S002 M04 Shana B+


I have a datasource from a single string delimited by special chars. Something like this.


S003@@@M02@@@Meru@@@C@@@S003@@@M03@@@Meru@@@S004@@@M01@@@Haschel@@@D


How do I insert that kind of string to the table?
Any answers or clue or reference greatly appreciated. Thank you in advance

The table looks like after insert:

student_id subject_id student_name student_report
S001 M01 Albert A+
S001 M02 Albert A
S002 M04 Shana B+
S003 M02 Meru C
S003 M02 Meru NULL //no data here
S004 M01 Haschel D

Answer

You need to split this string. Use explode function like this:

  $data = explode('@@@',$stingValue,);

$data will be having all the values. Open database connection, bind write a query, bind parameters and execute it.