I have a table in my MySQL database called studentname
.
I made an array in Javascript as var array1=["john","sam","peter","kelvin"];
I populated a select
box with these array values.
If the table studentname
contains names like "sam" and "peter", now I want to populate the select box with the values "john" and "kelvin" only, because "sam" and "peter" are already present in the database table.
How am I supposed to do this?
This is a three-step process:
- Modify your PHP script to connect to the database and retrieve the names from the 'studentname' table.
- Output the names as a separate Javascript array.
- When you create your select in Javascript, compare the values of array1 to the array created by your PHP code, and output only the elements that are unique.
精彩评论