php-newbies Posted March 12, 2012 Share Posted March 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/ Share on other sites More sharing options...
Muddy_Funster Posted March 12, 2012 Share Posted March 12, 2012 I'm sorry - what's this gotta do with PHP? Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326428 Share on other sites More sharing options...
cpd Posted March 12, 2012 Share Posted March 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326430 Share on other sites More sharing options...
php-newbies Posted March 12, 2012 Author Share Posted March 12, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326433 Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2012 Share Posted March 12, 2012 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.) Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326439 Share on other sites More sharing options...
php-newbies Posted March 12, 2012 Author Share Posted March 12, 2012 The output of the code is here http://tt.easy2sell.net Any suggestion or help will be highly appreciated. Many thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326498 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2012 Share Posted March 13, 2012 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.) Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326695 Share on other sites More sharing options...
PFMaBiSmAd Posted March 13, 2012 Share Posted March 13, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1326783 Share on other sites More sharing options...
php-newbies Posted March 13, 2012 Author Share Posted March 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1327003 Share on other sites More sharing options...
php-newbies Posted March 13, 2012 Author Share Posted March 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/258743-please-help-need-to-add-2-more-columns-to-this-code/#findComment-1327019 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.