keldorn Posted October 25, 2009 Share Posted October 25, 2009 Hey guys, I have a table looks like this +- Cat_Name (primary) - + recursive_id(int11) - ----------------------------- programming 1 xml 2 This is the Array that is returned from mysql_fetch_assoc(); Array ( [0] => Array ( [cat_name] => programming [recursive_id] => 1 ) [1] => Array ( [cat_name] => xml [recursive_id] => 2 ) ) I want to use it for recursive naming for categories. For example I have another table called "articles" inside it will say category= "1" or "2" etc, which I will compare to this array to get its name. How I can pull the array out to look like this?. So this makes more sense then quering the database multiple times to check the database table for its recursive name. Array ( [programming] => 1 [xml] => 2 ) Then I will be able to do this this to get the name easily.. $cat_name = $article['category']; // Is 1 $cat_name = $recursive_array[$cat_name]; // Sets to "programming" I can't to this with the array from mysql_fetch_assoc(); Quote Link to comment https://forums.phpfreaks.com/topic/178892-solved-recursive-naming-in-mysql-how/ Share on other sites More sharing options...
keldorn Posted October 25, 2009 Author Share Posted October 25, 2009 Never mind I just went ahead and created a little loop that recreates the array the way I want it. $bar = array(); $lorem = array(); foreach($foo as $bar){ $ipsum = $bar['cat_name']; if(!array_key_exists($ipsum,$lorem)){ $lorem[$ipsum] = $bar['recursive_id']; } } Quote Link to comment https://forums.phpfreaks.com/topic/178892-solved-recursive-naming-in-mysql-how/#findComment-943771 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.