Saturday, 15 March 2014

php - How find Row Number of Value within Array? -


I have saved all my data in an array, and I have to get the 'name' of a 'code'.

How do I get an array of that code?

Besides, is this the most efficient process?

  id Code | Name | __________________________ 1 | KNTY | Kentucky | 2 | PURD | Purdue 3 | Texans | Texas | // array $ search = "move data" "select from table"; $ Query = mysqli_query ($ conn, $ search); While ($ line = mysqli_fetch_assoc ($ query) {$ array [] = $ row; } // code I want a name for $ code = "KNTY"; // Mystery STEP I need help with $ name = $ array [$ id] ['name'];  

I edit with a commentary gesture. You can use the code as the key to the $ array :

  $ search = "Select from the table"; $ Query = mysqli_query ($ conn, $ search); $ Array = array (); While ($ line = mysqli_fetch_assoc ($ query)) {$ array [$ row ['code']] = $ row ['name']; } // code I want a name for $ code = "KNTY"; $ Name = $ array [$ code];  

No comments:

Post a Comment