I am using MySQL
and PHP CodeIgniter
.
I want to implement something like this:
---------------------------------------
Skill name: Photoshop | Skill level: 4
---------------------------------------
---------------------------------------
Skill name: CSS | Skill level: 3
---------------------------------------
---------------------------------------
Skill name: CorelDraw| Skill level: 4
---------------------------------------
I can easy print this in a single page. But I need it in a form somehow like this:
---------------------------------------
Skill name: [input] | Skill level: [input]
---------------------------------------
---------------------------------------
Skill name: [input] | Skill level: [input]
---------------------------------------
---------------------------------------
Skill name: [input] | Skill level: [input]
---------------------------------------
My database
for skills table is like this:
skill_id | user_id | skill_name | skill_level
I cannot figure it out how to insert each row with name and level into one DB row
Can you help me with this?
2
Answers
Not sure how this would work with whatever form/input framework CI provides but i would normall do this by naming the inputs with array notation:
After posting to PHP you would get an array like the following in
$_POST
:You can use
[]
-notation for input fields.As I suppose all your skills have ids, which are
skill_id
in a DB table.So, try creating a form like this:
Here, 23,25,27 are ids of your skills (for example), if you use existing skills in DB.
For newly created skills you can use @prodigitalson answer with 0,1,2… indexing.
Next you can iterate through
$_POST['skills']