Jump to content

noob in need of help. look to created dynamic variables


Recommended Posts


$output .= '<li class="'.$this_cat_class.'cat_lev_'.$level.'"><a class="link_lev_' .$level.'';

	$num_names = array(1, 2, 3, 4, 5, 6, 7, ;
	foreach ($num_names as $num_name)
	{
	$output .= '_' .$num_name. '';
	}
	$output .= '" ahref="';

 

returns: <li class="cat_lev_0"><a class="link_lev_0_1_2_3_4_5_6_7_8" ............

 

I need it to return a unique class each time it is used. The first time <a class="link_lev_0_1" .... second <a class="link_lev_0_2" .. and so on.

 

The code is within a while loop that builds each element of this list for each category returned from the database.

 

 

I assume by "return" you mean output?  Also, does "$this_cat_class" have a value?

 

Try this:

 

$num_names = array(1, 2, 3, 4, 5, 6, 7, ;
foreach ($num_names as $num_name)
{
$output_2 = "</pre>
<li class="'cat_lev_".$level."'">	echo $output_2;
}
?&gt

I'm going to post the whole script and what the output is to give you some more light on what I'm trying to do.

 

$GLOBALS['this_level'] = 0;

// Initialize HTML and info_box class if displaying inside a box
if ($show_ulcats_as_box) {
    echo '<tr><td>';
    $info_box_contents = array();
    $info_box_contents[] = array('text' => BOX_HEADING_CATEGORIES);
    new infoBoxHeading($info_box_contents, true, false);					
}

// Generate a bulleted list (uses configuration options above)
$categories_string = tep_make_cat_ullist();

// Output list inside a box if specified, otherwise just output unordered list
if ($show_ulcats_as_box) {
    $info_box_contents = array();
    $info_box_contents[] = array('text' => $categories_string);
    new infoBox($info_box_contents);
	echo '</td></tr>';	
} else {
	echo $before_nobox_html;	
    echo $categories_string;
	echo $after_nobox_html;
}


// Create the root unordered list
function tep_make_cat_ullist($rootcatid = 0, $maxlevel = 0){

    global $idname_for_menu, $cPath_array, $show_full_tree, $languages_id;

    // Modify category query if not fetching all categories (limit to root cats and selected subcat tree)
	if (!$show_full_tree) {
        $parent_query	= 'AND (c.parent_id = "0"';	

			if (isset($cPath_array)) {

			    $cPath_array_temp = $cPath_array;

			    foreach($cPath_array_temp AS $key => $value) {
					    $parent_query	.= ' OR c.parent_id = "'.$value.'"';
					}

					unset($cPath_array_temp);
			}	

        $parent_query .= ')';				
	} else {
        $parent_query	= '';	
	}

	$result = tep_db_query('select c.categories_id, cd.categories_name, c.parent_id from ' . TABLE_CATEGORIES . ' c, ' . TABLE_CATEGORIES_DESCRIPTION . ' cd where c.categories_id = cd.categories_id and cd.language_id="' . (int)$languages_id .'" '.$parent_query.' order by sort_order, cd.categories_name');
    
	while ($row = tep_db_fetch_array($result)) {				
        $table[$row['parent_id']][$row['categories_id']] = $row['categories_name'];
    }

    $output .= '<ul id="'.$idname_for_menu.'">';
    $output .= tep_make_cat_ulbranch($rootcatid, $table, 0, $maxlevel);

	// Close off nested lists
    for ($nest = 0; $nest <= $GLOBALS['this_level']; $nest++) {
        $output .= '</ul>';		
	}

    return $output;
}

// Create the branches of the unordered list
function tep_make_cat_ulbranch($parcat, $table, $level, $maxlevel) {

    global $cPath_array, $classname_for_selected, $classname_for_parent;

    $list = $table[$parcat];

    while(list($key,$val) = each($list)){

        if ($GLOBALS['this_level'] != $level) {

	        if ($GLOBALS['this_level'] < $level) {
			        $output .= "\n".'<ul>';
			    } else {
                for ($nest = 1; $nest <= ($GLOBALS['this_level'] - $level); $nest++) {
                    $output .= '</ul></li>'."\n";	
	            }
		}			

	        $GLOBALS['this_level'] = $level;
        }

        if (isset($cPath_array) && in_array($key, $cPath_array) && $classname_for_selected) {
            $this_cat_class = $classname_for_selected . ' ';
        } else {
            $this_cat_class = '';		
	    }	

        $output .= '<li class="'.$this_cat_class.'cat_lev_'.$level.'"><a class="link_lev_' .$level. '';


	$output .= '" ahref="';


        if (!$level) {
			    unset($GLOBALS['cPath_set']);
					$GLOBALS['cPath_set'][0] = $key;
            $cPath_new = 'cPath=' . $key;

        } else {
					$GLOBALS['cPath_set'][$level] = $key;		
            $cPath_new = 'cPath=' . implode("_", array_slice($GLOBALS['cPath_set'], 0, ($level+1)));
        }

        if (tep_has_category_subcategories($key) && $classname_for_parent) {
            $this_parent_class = ' class="'.$classname_for_parent.'"';
        } else {
            $this_parent_class = '';		
	    }				

        $output .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '"'.$this_parent_class.'>'.$val;		

/*        if (SHOW_COUNTS == 'true') {
            $products_in_category = tep_count_products_in_category($key);
            if ($products_in_category > 0) {
                $output .= ' ' .'</a>'. '<span></span>';
            }
        }*/

        $output .= ' ' .'</a>' . '<span></span>';	

        if (!tep_has_category_subcategories($key)) {
            $output .= '</li>'."\n";	
        }						 

        if ((isset($table[$key])) AND (($maxlevel > $level + 1) OR ($maxlevel == '0'))) {
            $output .= tep_make_cat_ulbranch($key,$table,$level + 1,$maxlevel);
        }
    
	} // End while loop

    return $output;
    
}	

 

The output:

<!-- start cat_list //-->
<ul id="nav">
<li class="cat_lev_0"><a class="link_lev_0" ahref="index.php?cPath=143&osCsid=dakc75je1f8jder1hk8qum7pu3" class="daddy">Ann Arbor </a><span></span>
<ul><li class="cat_lev_1"><a class="link_lev_1" ahref="index.php?cPath=143_147&osCsid=dakc75je1f8jder1hk8qum7pu3">Camps </a><span></span></li>
<li class="cat_lev_1"><a class="link_lev_1" ahref="index.php?cPath=143_148&osCsid=dakc75je1f8jder1hk8qum7pu3">Skill Development </a><span></span></li>
<li class="cat_lev_1"><a class="link_lev_1" ahref="index.php?cPath=143_145&osCsid=dakc75je1f8jder1hk8qum7pu3">Afterschool Hoops </a><span></span></li>
</ul></li>
<li class="cat_lev_0"><a class="link_lev_0" ahref="index.php?cPath=144&osCsid=dakc75je1f8jder1hk8qum7pu3">Saline </a><span></span></li>
</ul>
<!-- end cat_list //-->

 

All I need are specific class names on the a tag so I can manipulate them individually with CSS

 

 

I assume by "return" you mean output?  Also, does "$this_cat_class" have a value?

 

Try this:

 

<?php
$num_names = array(1, 2, 3, 4, 5, 6, 7, ;
foreach ($num_names as $num_name)
{
$output_2 = "<li class='cat_lev_".$level."'><a class='link_lev_'".$level."_".$num_name;
echo $output_2;
}
?>

 

this didn't work because it looped through them all, which is my fault because I didn't give you enough info

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.

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