Jump to content

[SOLVED] recursive naming in mysql, how?


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


    [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.


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






Link to comment
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'];


		  $lorem[$ipsum] = $bar['recursive_id']; 




Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.