dreamwest Posted November 6, 2010 Share Posted November 6, 2010 Im trying to get a name from an array Array ( [0] => Array ( [name] => acid jazz [id] => 32 ) [1] => Array ( [name] => african [id] => 78 ) [2] => Array ( [name] => alternative country [id] => 62 ) [3] => Array ( [name] => alternative dance [id] => 19 ) [4] => Array ( [name] => alternative metal [id] => 33 ) [5] => Array ( [name] => alternative rap [id] => 38 ) ) Basically all ive got is the id, so if array[5] has id of 38 i want to return the name, aka "alternative rap" Link to comment https://forums.phpfreaks.com/topic/217917-array/ Share on other sites More sharing options...
marcus Posted November 6, 2010 Share Posted November 6, 2010 echo $array[5]['name']; Link to comment https://forums.phpfreaks.com/topic/217917-array/#findComment-1130980 Share on other sites More sharing options...
dreamwest Posted November 6, 2010 Author Share Posted November 6, 2010 Close but i only have the id "38" not the array number, is there a way i can number the array so i can just call the name? Array ( [32] => Array ( [name] => acid jazz ) [78] => Array ( [name] => african ) [62] => Array ( [name] => alternative country ) [19] => Array ( [name] => alternative dance ) [4] => Array ( [name] => alternative metal [id] => 33 ) [38] => Array ( [name] => alternative rap ) ) Link to comment https://forums.phpfreaks.com/topic/217917-array/#findComment-1130982 Share on other sites More sharing options...
PFMaBiSmAd Posted November 6, 2010 Share Posted November 6, 2010 In you want to be able to lookup/convert any number of values on a page, you would build a simple key/value array (see the code in this post - http://www.phpfreaks.com/forums/php-coding-help/using-$row-and-changing-values/msg1484306/#msg1484306) If these are in a database and you are only getting one id/value on a page, you would do this in the query WHERE id = 38 Link to comment https://forums.phpfreaks.com/topic/217917-array/#findComment-1130985 Share on other sites More sharing options...
dreamwest Posted November 6, 2010 Author Share Posted November 6, 2010 Yeah i finally figured it out $res = mysql_query("SELECT * FROM styles_q"); while ($new = mysql_fetch_assoc( $res )){ $tmb[$new['st_id']] = array('name' => $new['st_name']); } echo $tmb['32']['name']; Link to comment https://forums.phpfreaks.com/topic/217917-array/#findComment-1130987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.