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.

31st May 2021, 10:34 PM
Md. Asiful Hoque Prodhan
Md. Asiful Hoque Prodhan - avatar
3 ответов
+ 1
I would just fetch all the rows, and then loop through it with a while loop and append to the array.
2nd Jun 2021, 5:55 AM
Benjamin Rogers
Benjamin Rogers - avatar
0
Benjamin Rogers Can you please give me the code snippet to do this?
4th Jun 2021, 10:39 PM
Md. Asiful Hoque Prodhan
Md. Asiful Hoque Prodhan - avatar
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.
5th Jun 2021, 12:03 AM
Benjamin Rogers
Benjamin Rogers - avatar