Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:39:47+00:00 2026-06-02T02:39:47+00:00

Is it possible to use two different foreach loops in one table with Smarty?

  • 0

Is it possible to use two different foreach loops in one table with Smarty?
I tried everything but it just doesnt seem to work. The $numrow array has 10 results, but only shows one and the same in all 10 rows.

Is this a common problem with Smarty?

<table width="500">   

{foreach from=$categories item=category}   
  {if $category.fcType == 'm'}
    <tr>
      <td><strong>{$category.fcName}</strong></td>
      <td>&nbsp</td>
  {else}
    <tr>
      <td><a href="http://localhost/ZendFramework/forum/category?c={$category.fcID}">{$category.fcName}</a></td>
      <td>{$category.fcDescription}</td>
    {foreach from=$numrows item=numrow} 
      <td>{$numrow}</td>
    {/foreach} 
  {/if}

  {if !empty($category.fuUsername)}
      <td>Nieuwste topic toegevoegd door {$category.fuUsername} op {$category.topic_date}</td>
  {else}
      <td>&nbsp</td> 
  {/if}
    </tr>        
{/foreach}  

</table>

php:

$getCat = isset($_GET['c']) ? $_GET['c'] : '';;
    $getCat = htmlentities(mysql_real_escape_string($getCat));;

    $query_cat = "
    SELECT 
        forum_categories.fcID
        ,forum_categories.fcName
        ,forum_categories.fcDescription
        ,forum_categories.fcParent
        ,forum_categories.fcType
        ,forum_users.fuUsername
        ,DATE_FORMAT(forum_topics.ftDate,'%d-%m-%Y %H:%i:%s') AS topic_date
    FROM
        forum_categories
    LEFT JOIN
        forum_topics
    ON
        forum_topics.fcID = forum_categories.fcID
    LEFT JOIN
        forum_users
    ON
        forum_topics.fuID = forum_users.fuID    
    GROUP BY
        forum_categories.fcID
    ORDER BY 
        forum_categories.fcPos 
    ";
    $exec_cat = mysql_query($query_cat);
    if (($exec_cat) and mysql_num_rows($exec_cat))
    {
        while($category = mysql_fetch_assoc($exec_cat))
        {           
            $query_count = "
            SELECT 
                forum_topics.ftID
            FROM
                forum_categories
            INNER JOIN
                forum_topics
            ON
                forum_categories.fcID = forum_topics.fcID
            WHERE forum_categories.fcID = '".$category['fcID']."'
            ";
            $exec_count = mysql_query($query_count);
            $numrows = mysql_num_rows($exec_count);
            $numrows[] = $numrows;

            echo $numrows;

            $this->view->assign("numrows", $numrows);   


            $categories[] = $category; 
            $this->view->assign("categories", $categories);
        }

    }  
    else 
    {
        echo 'Er zijn nog geen categorieen aanwezig in de database.';
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:39:48+00:00Added an answer on June 2, 2026 at 2:39 am
     while($category = mysql_fetch_assoc($exec_cat))
        {           
            $query_count = "
            SELECT 
                forum_topics.ftID
            FROM
                forum_categories
            INNER JOIN
                forum_topics
            ON
                forum_categories.fcID = forum_topics.fcID
            WHERE forum_categories.fcID = '".$category['fcID']."'
            ";
            $exec_count = mysql_query($query_count);
            $category['numrows'] = mysql_num_rows($exec_count);
            $categories[] = $category;
        }
    $this->view->assign("categories", $categories);
    

    And in your Smarty TPL: {foreach from=$category.numrows item=numrow}

    Aren’t you BTW overwriting your categories assign in your loop? (Place the last assign outside the while loop)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to just use this code alone to do two different regex
is it possible to use two different DataTemplates in one WPF TreeView? Maybe the
I want to use two meta:resourcekey in single control is it possible? for example
My use case expects heavy read load - there are two possible model design
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I
Is it possible use a MySQL query to perform this kind of check? If
I have recently started looking into Google Charts API for possible use within the
I need a control having these features: It should be possible use it in
Possible Duplicate: Use cases for IdentityHashMap What could be a practical use of the
Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.