alena1347 Posted January 25, 2013 Share Posted January 25, 2013 I am making a website having a "skills" field which is a dropdown menu dropdown menu which fetch's data from database and assign the Id to the option tag dynamically 1) I dont know if the id is assigned or not below is my code:- <select name="sname[]" id="sname" size="1" multiple="multiple" title="hold ctrl and click multiple options" > <?php include 'conn.php'; $que=mysql_query("select * from field"); while($row=mysql_fetch_array($que)) { $id=$row['id']; $field=$row['field']; echo "<option id="$id">".$field."</option>"; } ?> </select> 2)how do I insert multiple values of the option tag into the database into the database? Quote Link to comment https://forums.phpfreaks.com/topic/273616-insert-multiple-values-into-database/ Share on other sites More sharing options...
sowna Posted January 25, 2013 Share Posted January 25, 2013 As per your code, first point will work correctly if you have id and field column exists in the field table. Can you show me the fields in that table... For 2nd point, you can store values using comma separate ids, like, if you select two options whose ids will be 10 and 23 then in the database store 10,23. You can use implode() to convert array into comma separated string... Quote Link to comment https://forums.phpfreaks.com/topic/273616-insert-multiple-values-into-database/#findComment-1408100 Share on other sites More sharing options...
alena1347 Posted January 25, 2013 Author Share Posted January 25, 2013 (edited) As per your code, first point will work correctly if you have id and field column exists in the field table. Can you show me the fields in that table... For 2nd point, you can store values using comma separate ids, like, if you select two options whose ids will be 10 and 23 then in the database store 10,23. You can use implode() to convert array into comma separated string... 1)I have two fields "id" and "field" in this table 2)Thank you for the second point it solved my problem. Edited January 25, 2013 by alena1347 Quote Link to comment https://forums.phpfreaks.com/topic/273616-insert-multiple-values-into-database/#findComment-1408103 Share on other sites More sharing options...
Barand Posted January 25, 2013 Share Posted January 25, 2013 (edited) For 2nd point, you can store values using comma separate ids, like, if you select two options whose ids will be 10 and 23 then in the database store 10,23. You can use implode() to convert array into comma separated string... No No No! Doing it that way will destroy your ability to search your database by skills. You should store the skill ids in a separate table with each skill id in its own record with the id of the user/skill owner. user| skill ----|------ 1 | 1 1 | 2 1 | 3 2 | 2 2 | 4 @Sowna - read up on data normalization before you hand out any more advice on database design. Edited January 25, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/273616-insert-multiple-values-into-database/#findComment-1408132 Share on other sites More sharing options...
alena1347 Posted January 25, 2013 Author Share Posted January 25, 2013 No No No! Doing it that way will destroy your ability to search your database by skills. You should store the skill ids in a separate table with each skill id in its own record with the id of the user/skill owner. user| skill ----|------ 1 | 1 1 | 2 1 | 3 2 | 2 2 | 4 @Sowna - read up on data normalization before you hand out any more advice on database design. thanks Quote Link to comment https://forums.phpfreaks.com/topic/273616-insert-multiple-values-into-database/#findComment-1408140 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.