0
make another array from data returned by mysql_fetch_assoc() function
I have a student table on a MySQL database which consists of id and name column. I am using PHP. I can retrieve those column data using mysql_fetch_assoc() function. But I want to make an self defined array to map student name with id. For example, student("John")= 1, student("Michael")= 2 .... So that I can find id of any student just by giving their name.
3 Réponses
+ 1
I would just fetch all the rows, and then loop through it with a while loop and append to the array.
0
Benjamin Rogers Can you please give me the code snippet to do this?
0
Md. Asiful Hoque Prodhan Just curious why you're storing the results of the search into another array, mysql_fetch_assoc() already returns an array. And you could just use an sql query that searches based on name, and returns the id.