[Webinar] Streamline your web hosting managementRegister Today

x
  • 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
amenities1
amenities2
amenities3
amenities4
....
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:

<?

      require("libs/Smarty.class.php");      
      $smarty = new smarty;
      $smarty->allow_php_templates= true;
      $smarty->compile_check = true;
      $smarty->caching = true;
      $smarty->cache_lifetime = 100;

      
      include("dbconnect.php");
// 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;
      
      $i++;
      }
// smarty codes for amenities...
      $smarty->assign("amenitiesid"         , $arr_amenitiesid);
      $smarty->assign("amenitiesname"         ,$arr_amenitiesname);

      mysql_close($db_connect);
      
      $smarty->display('list_property_optional_details.tpl');      


?>

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

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
0
global_expert_advice
Asked:
global_expert_advice
  • 5
  • 2
  • 2
1 Solution
 
Ray PaseurCommented:
@jet-black: I see you, too, are a fan of LMGTFY

;-)

~Ray
0
 
jet-blackCommented:
@Ray_Paseur
I like it :)
0
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}
  <tr>
    {section name=td start=$smarty.section.tr.index
loop=$smarty.section.tr.index+$cols}
    <td>{$data[td]|default:"& nbsp;"}</td>      
    {/section}
  </tr>
  {/section}
</table>
0
 
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.
0
 
jet-blackCommented:
@Ray_Paseur
I totally agree and thank you for common sense.

@global_expert_advice
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:
elance.com
freelancer.com
scriptlance.com
rentacoder.com
0
 
jet-blackCommented:
unfair closing.
I have explained in detail in the message ID:26193361
0
 
global_expert_adviceAuthor Commented:
Partly accepted answer
0
 
jet-blackCommented:
@DropBearMod
Thank you.
0

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