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 7989883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:51:58+00:00 2026-06-04T12:51:58+00:00

I am having showing my results from Mysql database in Smarty.I assigned an array

  • 0

I am having showing my results from Mysql database in Smarty.I assigned an array to Smarty (before i tested this array in PHP with print_r) but after doing foreach loop in Smarty only one letter is shown.

Is there maybe something wrong in my while / foreach loop?
I did the assign to Smarty outside of it…

Thanks and greetz Eric

my PHP script:

        $query_main_category = "
        SELECT 
            webshop_products.wpID
            ,webshop_products.wpName
            ,webshop_products.wpDescription
            ,webshop_categories.wcName
        FROM
            webshop_products
        INNER JOIN
            webshop_product_category
        ON 
            webshop_products.wpID = webshop_product_category.wpcID
        INNER JOIN
            webshop_categories
        ON 
            webshop_product_category.wcID = webshop_categories.wcID  
        WHERE 
            webshop_categories.wcID = '1'
        ";
        $exec_main_category = mysql_query($query_main_category);
        if (($exec_main_category) and mysql_num_rows($exec_main_category))
        {
            while($list_products_category = mysql_fetch_assoc($exec_main_category))
            {
                $entries_product[] = $list_products_category; 
            }   
        }   

        $view_description = '';
        foreach($entries_product as $entry_product)
        {
            //If the description is more than 200 characters
            if (strlen($entry_product['wpDescription']) > 200) 
            {
                //Take the first 200 characters...
                $entry_product['wpDescription'] = substr($entry_product['wpDescription'], 0, 200);

                //Look for the last space in the description
                $temp = strrpos($entry_product['wpDescription'], ' ');

                //And cut everything after that point, and add three dots to show there's more
                $entry_product['wpDescription'] = substr($entry_product['wpDescription'], 0, $temp) . '...';
            }
            else
            {
                //If the description is <= 200 chars, show the whole description
                $entry_product['wpDescription'] = $entry_product['wpDescription'];
            }
        }
$this->view->assign('entry_product_smarty',$entry_product);

And Smarty:

<table>
    <tr>
        <td><strong>Titel</strong></td>     
        <td><strong>Omschrijving</strong></td>
    </tr>
    {foreach from=$entry_product_smarty item=entry_product}         
    <tr>
        <td>{$entry_product.wpName}</td>
        <td>{$entry_product.wpDescription}</td>
    </tr>
    {/foreach}

</table>
  • 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-04T12:51:59+00:00Added an answer on June 4, 2026 at 12:51 pm

    You assign the $entry_product instead of the $entries_product. In addition, you might want to change your foreach loop like the code below, otherwise it won’t have any effect:

            foreach($entries_product as $key => $entry_product)
            {
                //If the description is more than 200 characters
                if (strlen($entry_product['wpDescription']) > 200) 
                {
                    //Take the first 200 characters...
                    $entries_product[$key]['wpDescription'] = substr($entry_product['wpDescription'], 0, 200);
    
                    //Look for the last space in the description
                    $temp = strrpos($entry_product['wpDescription'], ' ');
    
                    //And cut everything after that point, and add three dots to show there's more
                    $entries_product[$key]['wpDescription'] = substr($entry_product['wpDescription'], 0, $temp) . '...';
                }
                else
                {
                    //If the description is <= 200 chars, show the whole description
                    $entries_product[$key]['wpDescription'] = $entry_product['wpDescription'];
                }
            }
            $this->view->assign('entry_product_smarty',$entries_product);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with showing how much time is left. This is my
Hey, well I'm having a problem and this weird symbol is showing up â€
This maybe the reason why I'm having problems in other areas, but which outputting
I have this php file. The lines marked as bold are showing up the
I´m having this issue, I did the mysql query inside a class and then
I'm having trouble getting the results I want from a Salesforce/Apex/SOQL query. I want:
i'm having an error showing : line 1:5 mismatched input '<EOF>' expecting NEWLINE for
I am having difficulty getting rid of duplicate entries which are showing up in
Having issues getting jQuery to work in this scenario: Visual Studio 2010 .Net 4.0
I've been using the following to create an array from a plist of dictionaries:

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.