Jump to content

[SOLVED] recursive naming in mysql, how?


keldorn

Recommended Posts

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();

 

:shrug:

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/178892-solved-recursive-naming-in-mysql-how/
Share on other sites

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']; 
		  
		}


}

 

:D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.