Jump to content

Insert multiple values into database


alena1347

Recommended Posts

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?

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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 by alena1347
Link to comment
Share on other sites

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 by Barand
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.