To anyone who want the same thing, follow my below steps.
I have a text file contains about 600+ names of schools and I want to make a schools-drop-down – So It’s very time-consuming to click add option one by one. It needs another way:
1. Content of The Schools list text file.
Tamale Polytechnic
Kumasi Polytechnic
Accra Polytechnic
Cape Coast Polytechnic
Koforidua Polytechnic
Ho Polytechnic
….600+…
2. I go to xProfile and create a Drop-down named it Schools – I input one option say “A sample school” – save.
3. I go to phpMyadmin -to Database to table gsl_bp_xprofile_fields – Search “A sample school” to find the newly created Sample schools row – on the result look at the
columns: (group_id, parent_id, type , name) . they should have values like: (group_id: 1, parent_id: 127,type :’option’ ,name :’A sample school’).
4. Next I use a Core Java code(because I don’t know how to do this in PHP) to read the schools list text file one by one and custom the print out like this:
String fileName = "D://Schools.txt";
String line = null;
try {
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
line = line.replace("'", "");
String sqlBase = "INSERT INTO gsl_bp_xprofile_fields (group_id,parent_id, type,name) VALUES (1, 127,'option' ,"+"'"+line+"'"+");";
System.out.println(sqlBase);
}
bufferedReader.close();
}
After running the above code I have a list of SQL insert commands printed on my eclipse they look like this:
INSERT INTO gsl_bp_xprofile_fields (group_id,parent_id, type,name) VALUES (1, 127,'option' ,'Tamale Polytechnic');
INSERT INTO gsl_bp_xprofile_fields (group_id,parent_id, type,name) VALUES (1, 127,'option' ,'Kumasi Polytechnic');
INSERT INTO gsl_bp_xprofile_fields (group_id,parent_id, type,name) VALUES (1, 127,'option' ,'Accra Polytechnic');
….many more insert commands until the end of the schools file 600+
5. Next, I copy all these commands, come back phpMyadmin database- table gsl_bp_xprofile_fields – to SQL tab, paste all commands, click run/go to insert all the options.
That’s all done for me!