Jump to content

Please help, need to add 2 more columns to this code


php-newbies

Recommended Posts

Hi all,

 

This application is given me a nightmare. The code fetches root categories and its sub categories from the a database table. The div table have only 2 columns. I want to add 2 extra columns so that I have 4 columns. Because we have a long list of subcategories meaning I have to scroll down to view the category. Please help

 

{include file='t_javascript_language.tpl'}
{set_css}
{set_js}

<!--<div class="componentheading">{$page_title}</div>-->

<div class="adds_man_list">
<span>{$category_pathway}</span>
{if $current_category->catname!=""}
<div style="border:2px solid #000;">
	{include file='elements/display_fields.tpl' position='categoryicon' this_add=$current_category->id}

	<strong>{$current_category->catname}</strong>

	<div class="adds_subcat" style="text-align:right;background:#F5F5F5; border:1px solid #FFFFFF; " >

	{include file='elements/display_fields.tpl' position='categorydetails' this_add=$current_category->id}

	<span style="font-size:12px;">

	{jtext text="ADS_SUBCATEGORIES"}:   {$current_category->kids} {jtext text="ADS_ADS"}: {$current_category->nr_ads}
		<a href="{$current_category->view}" title="{jtext text='ADS_VIEW_LISTINGS'}">
			<img src="{$IMAGE_ROOT}view_listings.gif" class="ads_noborder" alt="{jtext text='ADS_VIEW_LISTINGS'}" />
		</a>					
	</span>
	</div>
</div>
{/if}	
{if $categories|@count<=0}
	<h2>{jtext text="ADS_NO_CATEGORIES_DEFINED"}</h2>
{/if}
<table id="adds_categories" class="ads_table">
{section name=category loop=$categories}
{if $smarty.section.category.rownum is odd}
	<tr>
{/if}
		<td width="50%" class="adsman_catcell" valign="top">
			<div class="adds_maincat" {if $categories[category]->watchListed_flag}class="cat_watchlist"{/if}> 

				{include file='elements/display_fields.tpl' position='categoryicon' this_add=$categories[category]->id}
				<a href="{if $categories[category]->kids>0}{$categories[category]->link}{else}{$categories[category]->view}{/if}" >
					{$categories[category]->catname}
				</a>
				{if $categories[category]->is_new}
					<!--NEW!!-->
					<img src="{$IMAGE_ROOT}new.png" alt="new ads" />
				{/if}
				<a href="{$categories[category]->view}" title="{jtext text='ADS_VIEW_LISTINGS'}">
					<img src="{$IMAGE_ROOT}view_listings.gif" class="ads_noborder" alt="{jtext text='ADS_VIEW_LISTINGS'}" />
				</a>					
				{if $is_logged_in}
					{if $categories[category]->watchListed_flag}
						<img src="{$IMAGE_ROOT}watchlist.png" width="16"class="ads_noborder" />
					{/if}
					<a href="{$categories[category]->link_watchlist}">
						<img src="{$categories[category]->img_src_watchlist}" width="16" class="ads_noborder" title="{if $categories[category]->watchListed_flag}{jtext text='ADS_REMOVE_FROM_WATCHLIST'}{else}{jtext text='ADS_ADD_TO_WATCHLIST'}{/if}"/>
					</a>
				{/if}
				<br />
			</div>

			<div class="adds_subcat" style="background:#F5F5F5; border:1px solid #FFFFFF; " >
			{include file='elements/display_fields.tpl' position='categorydetails' this_add=$categories[category]->id}
			<br />

			{section name=subcategory loop=$categories[category]->subcategories}

				{include file='elements/display_fields.tpl' position='categoryicon' this_add=$categories[category]->subcategories[subcategory]->id}
				<a href="{if $categories[category]->subcategories[subcategory]->kids>0}{$categories[category]->subcategories[subcategory]->link}{else}{$categories[category]->subcategories[subcategory]->view}{/if}">{$categories[category]->subcategories[subcategory]->catname}</a> 
				{if $categories[category]->subcategories[subcategory]->is_new==1}
					<img src="{$IMAGE_ROOT}new.png" alt="new ads" />
			 	 {/if}
					({$categories[category]->subcategories[subcategory]->nr_a} {jtext text="ADS_ADS"})
				{if $categories[category]->subcategories[subcategory]->watchListed_flag}
					<img src="{$IMAGE_ROOT}watchlist.png" width="16" class="ads_noborder" />
				{/if}
				{if $is_logged_in}
				<a href="{$categories[category]->subcategories[subcategory]->link_watchlist}">
					<img src="{$categories[category]->subcategories[subcategory]->img_src_watchlist}" width="14" class="ads_noborder" title="{if $categories[category]->subcategories[subcategory]->watchListed_flag}{jtext text='ADS_REMOVE_FROM_WATCHLIST'}{else}{jtext text='ADS_ADD_TO_WATCHLIST'}{/if}"/>
				</a>
				{/if}
				<br />
				<p style="margin-left:25px;">
				{include file='elements/display_fields.tpl' position='categorydetails' this_add=$categories[category]->id}
				</p>
			{/section}
			</div>
		</td>
	{if $smarty.section.category.rownum is not odd}
	</tr>
	{/if}
{/section}
</table>
</div>

 

Many thanks

Link to comment
Share on other sites

If my memory serves me correctly, he's using the smarty engine (pile of junk that it is, apologies if I offend anyone).

 

You'll need to add some HTML like <td></td> to add an additional column in your table; however there are a lot of smarty if statements between your table data tags at the moment so getting the right content in the right place may be a rather tedious task.

Link to comment
Share on other sites

If my memory serves me correctly, he's using the smarty engine (pile of junk that it is, apologies if I offend anyone).

 

You'll need to add some HTML like <td></td> to add an additional column in your table; however there are a lot of smarty if statements between your table data tags at the moment so getting the right content in the right place may be a rather tedious task.

 

No you are not offending anyone. It is a nightmare for me trying to add the extra column, just don't know how. I did not even realize the extension is a tpl. Well any help will be highly appreciated. Thanks for the help so far

Link to comment
Share on other sites

The following two sections of code are what start a new row and end a row. Since they operate on odd/not-odd (even), you get two categories per row -

 

{if $smarty.section.category.rownum is odd}
<tr>
{/if}

 

{if $smarty.section.category.rownum is not odd}
</tr>
{/if}

 

You would need to use the rownum and a modulus operator or a second counter to do a specific number of categories per row (since I don't know anything about smarty's syntax, that is all I can specifically help with.)

Link to comment
Share on other sites

See this link for several ways of producing  a variable number of columns - http://smarty.incutio.com/?page=SmartyColumnsTutorial

 

The Simpler Solution Using Smarty 2.6 Embedded Math example at the link is probably the best fit (it uses a separate counter to determine when to start/end a row.

 

One theme that is in the examples in that link is to finish the last table row, which could be partial row if there is not exactly enough data (your existing code, as far as I looked at it, also suffers from not completing the last row if there is only one data item in it.)

Link to comment
Share on other sites

Untested, but should work (you will need to set the $numCols variable) -

 

{include file='t_javascript_language.tpl'}
{set_css}
{set_js}

<!--<div class="componentheading">{$page_title}</div>-->

<div class="adds_man_list">
<span>{$category_pathway}</span>
{if $current_category->catname!=""}
<div style="border:2px solid #000;">
	{include file='elements/display_fields.tpl' position='categoryicon' this_add=$current_category->id}

	<strong>{$current_category->catname}</strong>

	<div class="adds_subcat" style="text-align:right;background:#F5F5F5; border:1px solid #FFFFFF; " >

	{include file='elements/display_fields.tpl' position='categorydetails' this_add=$current_category->id}

	<span style="font-size:12px;">

	{jtext text="ADS_SUBCATEGORIES"}:   {$current_category->kids} {jtext text="ADS_ADS"}: {$current_category->nr_ads}
		<a href="{$current_category->view}" title="{jtext text='ADS_VIEW_LISTINGS'}">
			<img src="{$IMAGE_ROOT}view_listings.gif" class="ads_noborder" alt="{jtext text='ADS_VIEW_LISTINGS'}" />
		</a>					
	</span>
	</div>
</div>
{/if}	
{if $categories|@count<=0}
	<h2>{jtext text="ADS_NO_CATEGORIES_DEFINED"}</h2>
{/if}
<table id="adds_categories" class="ads_table">
  <tr>
  {assign var="col" value="0"}
  {section name=category loop=$categories}
	{if $col == $numCols}
            </tr><tr>{assign var="col" value="0"}
        {/if}
		<td width="50%" class="adsman_catcell" valign="top">
			<div class="adds_maincat" {if $categories[category]->watchListed_flag}class="cat_watchlist"{/if}> 

				{include file='elements/display_fields.tpl' position='categoryicon' this_add=$categories[category]->id}
				<a href="{if $categories[category]->kids>0}{$categories[category]->link}{else}{$categories[category]->view}{/if}" >
					{$categories[category]->catname}
				</a>
				{if $categories[category]->is_new}
					<!--NEW!!-->
					<img src="{$IMAGE_ROOT}new.png" alt="new ads" />
				{/if}
				<a href="{$categories[category]->view}" title="{jtext text='ADS_VIEW_LISTINGS'}">
					<img src="{$IMAGE_ROOT}view_listings.gif" class="ads_noborder" alt="{jtext text='ADS_VIEW_LISTINGS'}" />
				</a>					
				{if $is_logged_in}
					{if $categories[category]->watchListed_flag}
						<img src="{$IMAGE_ROOT}watchlist.png" width="16"class="ads_noborder" />
					{/if}
					<a href="{$categories[category]->link_watchlist}">
						<img src="{$categories[category]->img_src_watchlist}" width="16" class="ads_noborder" title="{if $categories[category]->watchListed_flag}{jtext text='ADS_REMOVE_FROM_WATCHLIST'}{else}{jtext text='ADS_ADD_TO_WATCHLIST'}{/if}"/>
					</a>
				{/if}
				<br />
			</div>

			<div class="adds_subcat" style="background:#F5F5F5; border:1px solid #FFFFFF; " >
			{include file='elements/display_fields.tpl' position='categorydetails' this_add=$categories[category]->id}
			<br />

			{section name=subcategory loop=$categories[category]->subcategories}

				{include file='elements/display_fields.tpl' position='categoryicon' this_add=$categories[category]->subcategories[subcategory]->id}
				<a href="{if $categories[category]->subcategories[subcategory]->kids>0}{$categories[category]->subcategories[subcategory]->link}{else}{$categories[category]->subcategories[subcategory]->view}{/if}">{$categories[category]->subcategories[subcategory]->catname}</a> 
				{if $categories[category]->subcategories[subcategory]->is_new==1}
					<img src="{$IMAGE_ROOT}new.png" alt="new ads" />
			 	 {/if}
					({$categories[category]->subcategories[subcategory]->nr_a} {jtext text="ADS_ADS"})
				{if $categories[category]->subcategories[subcategory]->watchListed_flag}
					<img src="{$IMAGE_ROOT}watchlist.png" width="16" class="ads_noborder" />
				{/if}
				{if $is_logged_in}
				<a href="{$categories[category]->subcategories[subcategory]->link_watchlist}">
					<img src="{$categories[category]->subcategories[subcategory]->img_src_watchlist}" width="14" class="ads_noborder" title="{if $categories[category]->subcategories[subcategory]->watchListed_flag}{jtext text='ADS_REMOVE_FROM_WATCHLIST'}{else}{jtext text='ADS_ADD_TO_WATCHLIST'}{/if}"/>
				</a>
				{/if}
				<br />
				<p style="margin-left:25px;">
				{include file='elements/display_fields.tpl' position='categorydetails' this_add=$categories[category]->id}
				</p>
			{/section}
			</div>
		</td>
        {assign var="col" value="`$col+1`"}
{/section}
    {assign var="remainder" value="`$numCols-$col`"}
    {section name=emptyElement loop=$remainder}
        <td> </td>
    {/section}
</tr>
</table>
</div>

Link to comment
Share on other sites

Thank you so much, the code added 3 extra columns. The widths are not even. Trying to figure out how make the columns width the same width. It will definitively looks good when it finished. I really appreciate all your effort in modifying the code. I did not add any variable, I am a bit unsure about it.

Link to comment
Share on other sites

Thanks again for your help. Just an update, the code is adding extra rows each time I add a new category. I wanted to have 4 fixed columns and unlimited number of rows. Perhaps it is because I did not specify a variable for numCols as I am unsure about that.

 

 

I really appreciate all your effort in modifying the code.

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.

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.