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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:53:09+00:00 2026-06-18T11:53:09+00:00

I am trying to use smarty for a new website but I have a

  • 0

I am trying to use smarty for a new website but I have a little problem assign data from a sql query to a smartyt foreach loop. I do not get any data from the query to my template.

In my class.designs.php I have this:

    function listAllDesigns() {
            global $db;

            $row = $db->query("
SELECT ds.*, count(com.comment) AS countcom 
FROM designs ds LEFT JOIN comments com ON com.design_id = ds.id 
WHERE ds.approved = 1 
GROUP BY ds.id 
ORDER BY ds.date_added ASC")->resultset();        

            $smarty = new Smarty;        
            $smarty->assign('designs', $row);

            return;        
        }

and my index.php

include_once("includes/connect.php"); //Database connection
include_once("includes/config.php"); //Configuration file
include_once("includes/classes/class.designs.php"); //Main design class

require('smarty/libs/Smarty.class.php');

$designs = new Designs();
$designs->listAllDesigns();

$smarty = new Smarty;
$smarty->debugging = true;
$smarty->caching = true;
$smarty->cache_lifetime = 120;

$smarty->assign("charset", $config->charset);
$smarty->assign("pagetitle", $config->pagetitle);
$smarty->display('index.tpl');

and in index.tpl I have this:

{foreach $designs as $r}
  <li>{$r.name}</li>
{foreachelse}
   No results 
{/foreach}

It just print “No result” and I am getting a “Undefined index designs” error.

  • 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-18T11:53:10+00:00Added an answer on June 18, 2026 at 11:53 am
    include_once("includes/connect.php"); //Database connection
    include_once("includes/config.php"); //Configuration file
    include_once("includes/classes/class.designs.php"); //Main design class
    
    require('smarty/libs/Smarty.class.php');
    
    $designs = new Designs();
    $designs->listAllDesigns();
    
    $smarty = new Smarty;
    $smarty->debugging = true;
    $smarty->caching = true;
    $smarty->cache_lifetime = 120;
    
    // TO USE some value ($designs in your case) at your template you must assign it
    // 1st is its name and 2nd is the value
    $smarty->assign("designs", $designs);
    
    $smarty->assign("charset", $config->charset);
    $smarty->assign("pagetitle", $config->pagetitle);
    $smarty->display('index.tpl');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the New Methods for National Character Set Type Data
I am trying use gem tire to search in my application. I have tables
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
Hi I'm trying use a datepicker on a field I have. I'm trying to
I am trying to use smarty variables inside javascript inside tpl {literal} <script language=javascript>
I am trying to use std::shared_ptr in my code. I have seen there have
Background: I have been charged with trying to come up with a new way
Im pretty much new to data mining and recommendation systems, now trying to build
Good morning all, I'm trying to use a smarty MySql one-line that will do

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.