|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Yupy Smarty n00b
Joined: 26 Jul 2012 Posts: 4
|
Posted: Tue Mar 25, 2014 8:10 pm Post subject: Loop Question (HELP !!!) |
|
|
How can i make it look like this:
Instead of this:
My code:
Code: | $res = $db->query("SELECT id, name, image
FROM categories
ORDER BY id ASC") or $db->error();
$count = $res->num_rows;
if ($count > 0)
{ /*
print("<table class='main' border='1' align='center' cellspacing='0' cellpadding='5'>");
print("<tr>");
print("<td class='colhead'>ID</td>");
print("<td class='colhead'>Cat Name</td>");
print("<td class='colhead'>Cat Image</td>");
print("<td class='colhead' align='center' colspan='2'>Action</td>");
print("</tr>");
*/
while ($arr = $res->fetch_assoc())
{
$smarty->assign("cat", array("id" => $arr["id"],
"name" => $arr["name"],
"imgdir" => $image_dir,
"image" => $arr["image"]));
$smarty->display('admincp/current_categories.tpl');
}
} |
TPL:
Code: | <table class='main' border='1' align='center' cellspacing='0' cellpadding='5'>
<tr>
<td class='colhead'>ID</td>
<td class='colhead'>Cat Name</td>
<td class='colhead'>Cat Image</td>
<td class='colhead' align='center' colspan='2'>Action</td>
</tr>
<tr>
<td class='rowhead' align='center'><a href='browse.php?cat={$cat.id}'>{$cat.id}</a></td>
<td class='rowhead' align='center'><a href='browse.php?cat={$cat.id}'>{$cat.name}</a></td>
<td class='rowhead' align='center'>
<a href='browse.php?cat={$cat.id}'>
<img src='{$cat.imgdir}caticons/{$cat.image}' width='60' height='54' border='0' alt='{$cat.name}' title='{$cat.name}' />
</a>
</td>
<td class='rowhead' align='center'>
<a href='controlpanel.php?fileaction=8&action=edit&cid={$cat.id}'>
<img src='{$cat.imgdir}edit.png' width='16' height='16' border='0' alt='Edit Category' title='Edit Category' style='border:none;padding:3px;' />
</a>
</td>
<td class='rowhead' align='center'>
<a href='controlpanel.php?fileaction=8&action=delete&cid={$cat.id}'>
<img src='{$cat.imgdir}delete.png' width='16' height='16' border='0' alt='Drop Category' title='Drop Category' style='border:none;padding:3px;' />
</a>
</td>
</tr> |
Any idea? I really need how to figure this out. Thanks. |
|
Back to top |
|
srikanthg Smarty n00b
Joined: 18 Mar 2014 Posts: 2 Location: Hyderabad
|
Posted: Thu Mar 27, 2014 10:24 am Post subject: dont put header code inside loop |
|
|
<tr>
<td class='colhead'>ID</td>
<td class='colhead'>Cat Name</td>
<td class='colhead'>Cat Image</td>
<td class='colhead' align='center' colspan='2'>Action</td>
</tr>
take this out of the loop |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 27, 2014 5:39 pm Post subject: |
|
|
This part:
Code: | {
$smarty->assign("cat", array("id" => $arr["id"],
"name" => $arr["name"],
"imgdir" => $image_dir,
"image" => $arr["image"]));
$smarty->display('admincp/current_categories.tpl');
} |
Is assigning the values over one another. You need to accumulate them. Something like:
Code: | foreach(..) {
$records[] = array("id" => $arr["id"],
"name" => $arr["name"],
"imgdir" => $image_dir,
"image" => $arr["image"]));
}
$smarty->assign('records', $records);
|
Then loop the data in the template:
Code: | {foreach $records as $record} ... {/foreach} |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|