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
https://forums.phpfreaks.com/topic/273616-insert-multiple-values-into-database/
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...

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.

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.

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

Archived

This topic is now archived and is closed to further replies.

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