Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Loop Question (HELP !!!)

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Yupy
Smarty n00b


Joined: 26 Jul 2012
Posts: 4

PostPosted: Tue Mar 25, 2014 8:10 pm    Post subject: Loop Question (HELP !!!) Reply with quote

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&amp;action=edit&amp;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&amp;action=delete&amp;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
View user's profile Send private message
srikanthg
Smarty n00b


Joined: 18 Mar 2014
Posts: 2
Location: Hyderabad

PostPosted: Thu Mar 27, 2014 10:24 am    Post subject: dont put header code inside loop Reply with quote

<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
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Mar 27, 2014 5:39 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP