[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1013
  • Last Modified:

passing data arrays to multiple columns using smarty php and mysql

dear experts,
After a long try, i got 90% success in what i'm trying to acheive.
What i want?
is to display the list of all the features from amenities column of my database in to 3 or 4 columns.
in regular sql query we get like
but i want in this manner
amenities 1          amenites2       amenities3
amenities 4          amenites5       amenities6
amenities 7          amenites8       amenities9

I want this in smarty way...
the code which i'm using is giving all the 11 columns instead dividing them to 3 columns.

My code is below
smarty code:


      $smarty = new smarty;
      $smarty->allow_php_templates= true;
      $smarty->compile_check = true;
      $smarty->caching = true;
      $smarty->cache_lifetime = 100;

// Amenities
      $i = 0;
      $amenities_query = "SELECT id,amenities FROM amenities";
      $amenitiesresult = mysql_query($amenities_query) or die(mysql_error());
      while ($row = mysql_fetch_array($amenitiesresult))
      $amenitiesid = $row['id'];
      $amenitiesname = $row['amenities'];
      $columns = '4';
      $arr_amenitiesid[$i]            = $amenitiesid;
      $arr_amenitiesname[$i]            = $amenitiesname;
// smarty codes for amenities...
      $smarty->assign("amenitiesid"         , $arr_amenitiesid);
      $smarty->assign("amenitiesname"         ,$arr_amenitiesname);



list_property_optional_details.tpl code
    {assign var="col" value="0"}
    {section name=element loop=$amenitiesname}
        {if $col == $columns}
            </tr><tr>{assign var="col" value="0"}
        <td><input type="checkbox" name="C9" value="{$amenitiesname[element]}">{$amenitiesname[element]}</td>
        {assign var="col" value="'$col+1'"}
    {assign var="remainder" value="'$columns-$col"}
    {section name=emptyElement loop=$remainder}

Could any of the smarty expert let me know how solve this problem...
In reply please explain with modified code..
A quick reply will be much appreciated
  • 5
  • 2
  • 2
1 Solution
Ray PaseurCommented:
@jet-black: I see you, too, are a fan of LMGTFY


I like it :)
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

global_expert_adviceAuthor Commented:
thanks for post you did...
solving the problem is important rather giving url links..
searching i too can do... but what i asked is to solve the above error..
I rectified the problem self... and here is the solution

{* $cols is the number of columns you want *}
<table border=1>
  {section name=tr loop=$data step=$cols}
    {section name=td start=$smarty.section.tr.index
    <td>{$data[td]|default:"& nbsp;"}</td>      
Ray PaseurCommented:
@global_expert_advice: I do not really have a dog in this hunt, so I am not going to object, but I think jet-black did EXACTLY the right thing for you, which is point you to a learning resource.  Obviously you had not found those resources before jet-black pointed you to them.  

Many of us here are professional programmers, and we do not write other people's code for free - we get paid to do that.  The spirit of EE seems to work best when we teach a man to fish, rather than give him a dead fish.
I totally agree and thank you for common sense.

This site helps programmers to find a solution. Most times giving a link exactly does that.

If you want someone to write code for you, here is the list of these type of popular websites:
unfair closing.
I have explained in detail in the message ID:26193361
global_expert_adviceAuthor Commented:
Partly accepted answer
Thank you.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now