global_expert_advice
asked on
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_templat es= 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_que ry) or die(mysql_error());
while ($row = mysql_fetch_array($ameniti esresult))
{
$amenitiesid = $row['id'];
$amenitiesname = $row['amenities'];
$columns = '4';
$arr_amenitiesid[$i] = $amenitiesid;
$arr_amenitiesname[$i] = $amenitiesname;
$i++;
}
// smarty codes for amenities...
$smarty->assign("amenities id" , $arr_amenitiesid);
$smarty->assign("amenities name" ,$arr_amenitiesname);
mysql_close($db_connect);
$smarty->display('list_pro perty_opti onal_detai ls.tpl');
?>
list_property_optional_det ails.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[ele ment]}">{$ amenitiesn ame[elemen t]}</td>
{assign var="col" value="'$col+1'"}
{/section}
{assign var="remainder" value="'$columns-$col"}
{section name=emptyElement loop=$remainder}
<td> </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
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
$smarty = new smarty;
$smarty->allow_php_templat
$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_que
while ($row = mysql_fetch_array($ameniti
{
$amenitiesid = $row['id'];
$amenitiesname = $row['amenities'];
$columns = '4';
$arr_amenitiesid[$i] = $amenitiesid;
$arr_amenitiesname[$i] = $amenitiesname;
$i++;
}
// smarty codes for amenities...
$smarty->assign("amenities
$smarty->assign("amenities
mysql_close($db_connect);
$smarty->display('list_pro
?>
list_property_optional_det
<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[ele
{assign var="col" value="'$col+1'"}
{/section}
{assign var="remainder" value="'$columns-$col"}
{section name=emptyElement loop=$remainder}
<td> </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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@Ray_Paseur
I like it :)
I like it :)
ASKER
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.i ndex
loop=$smarty.section.tr.in dex+$cols}
<td>{$data[td]|default:"& nbsp;"}</td>
{/section}
</tr>
{/section}
</table>
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.i
loop=$smarty.section.tr.in
<td>{$data[td]|default:"& nbsp;"}</td>
{/section}
</tr>
{/section}
</table>
@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.
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.
@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
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
unfair closing.
I have explained in detail in the message ID:26193361
I have explained in detail in the message ID:26193361
ASKER
Partly accepted answer
@DropBearMod
Thank you.
Thank you.
;-)
~Ray