Saturday 15 January 2011

php - Data not being displayed in tabs -



php - Data not being displayed in tabs -

i displaying info database linked cms. problem info 1 of tabs beingness displayed. suppose have 2 tabs, tab 1, tab 2. instead of tab 1 beingness active, tab 2 active , info displayed of tab 2. but, when click on tab 1, no info respect tab 1 displayed. same info nowadays i.e tab 2 data. using mapping ids of respective tab.

<ul class="tabs" data-tab> <?php if(isset($x['list_by_parent_id'][0]) && !empty($x['list_by_parent_id'][0])) { $top_category_index=1; foreach ($x['list_by_parent_id'][0] $category_id) { ?> <li class="tab-title <?php if($top_category_index==1){ echo "active"; }?>"><a href="#category-<?php echo $top_category_index++ ?>" class="category-name"><?php echo $site['tmp']['product_categories'][$category_id] ?></a></li> <?php } } ?> </ul>

x global variable array , stores everything.

this code mapping , displays content.

<div class="category-content"> <div class="menu-cat-content tabs-content"> <?php if(isset($site['category_list_by_parent_id'][0]) && !empty($site['category_list_by_parent_id'][0])) { $top_category_index_mapped=1; foreach ($site['category_list_by_parent_id'][0] $category_id) { ?> <div id="category-<?php echo $top_category_index_mapped; ?>" class="content <?php if($top_category_index_mapped++==1) { ?>active<?php } ?>"> //code content </div>

rendered html:

<div class="category-content"> <div class="menu-cat-content tabs-content"> <div id="category-1" class="content active"> <!--sub category 1--> </div><!--sub-category-clearfix2--> <!--sub category 2 ends--> </div> <!--category-div, index_mapped --> <div id="category-2" class="content active"> <!--sub category 1--> </div><!--sub-category-clearfix2--> <!--sub category 2 ends--> </div> <!--category-div, index_mapped --> <div id="category-3" class="content active">

edit: saw top_category_index_mapped set 1 in category-*top_category_index_mapped. replaced , rendered html looks this.

this line:

$top_category_index=1;

sets $top_category_index 1 first tab. line:

<li class="tab-title <?php if($top_category_index==1){ echo "active"; }?>

is equal firs 2 times:

<li class="tab-title active">

because of properties of ++ operator. read more here.

for example:

$a = 5; echo "should 5: " . $a++ . "<br />\n"; echo "should 6: " . $a . "<br />\n";

since you've tested 2 tabs seems, that's why getting results. might helpful include rendered html.

php html css

No comments:

Post a Comment