title: working with smarty and mysql database?
body: <p>this is the first time that I need to work with <code>smarty</code> and it seems quite straight forward.</p>
  
  <p>however, there is <em>twist</em> in my PHP code and that is causing an issue.</p>
  
  <p>here is what I am trying to do:</p>
  
  <p><em>Before you start beating me for not using mysqli functions etc, please note that this code is just a simple test for me to understand the smarty first. so i won't be using mysql in my project and I do not recommend anyone to do so...</em></p>
  
  <p>any way, here is  what I am trying to do:</p>
  
  <p>I am using the following code in my <code>index.php</code> page:</p>
  
  <pre><code>&lt;?php
  header("Content-type: text/html; charset=utf-8");
  function isSubdomain()
  {
      $host = $_SERVER['HTTP_HOST'];
      $host = explode('.',$host);
      $host = (is_array($host)?$host[0]:$host);
      return $host;
  }
  ?&gt;
  &lt;?php
  // These are the smarty files
  require 'libs/Smarty.class.php';
  
  // This is a file which abstracts the DB connecting functionality (Check out PEAR)
  include "config/connect_to_mysql.php";
  
  $smarty = new Smarty;
  
  $smarty-&gt;compile_check = true;
  $smarty-&gt;debugging = false;
  $smarty-&gt;use_sub_dirs = false;
  $smarty-&gt;caching = true;
  
  // This SQL statement will get the 5 most recently added new items from the database
  
  $storeShop = isSubdomain();
  echo $storeShop;
  
  $sql = 'SELECT * ';
  $sql .= 'FROM $storeShop ';
  $sql .= 'ORDER BY `id` ';
  
  $result = mysql_query($sql) or die("Query failed : " . mysql_error());
  
  // For each result that we got from the Database
  while ($line = mysql_fetch_assoc($result))
  {
   $value[] = $line;
  }
  
  // Assign this array to smarty...
  $smarty-&gt;assign('storeShop', $value);
  
  
  
  // Assign this array to smarty...
  $smarty-&gt;assign('$storeShop', $value);
  
  // Display the news page through the news template
  $smarty-&gt;display('index.tpl');
  
  // Thanks to David C James for a code improvement :)
  ?&gt;
  </code></pre>
  
  <p>and this is the <code>index.tpl</code> file:</p>
  
  <pre><code>&lt;!-- This is the DOC type declaration and links in the CSS stylesheet etc --&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt;
    &lt;head&gt;
      &lt;meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" /&gt;
      &lt;meta name="author" content="Steve Rendell" /&gt;
      &lt;meta name="generator" content="EditPlus" /&gt;
      &lt;link rel="stylesheet" type="text/css" href="style.css" title="Default CSS Sheet" /&gt;
  
      &lt;title&gt;News Page&lt;/title&gt;
    &lt;/head&gt;
  
    &lt;body id="top"&gt;
  
      &lt;!-- OK display the page header to keep it nice--&gt;
      &lt;div id="header"&gt;
        &lt;span&gt;Steve's News Page&lt;/span&gt;
      &lt;/div&gt;
  
      &lt;!-- This is where the news article will be going --&gt;
      &lt;div id="bodyText"&gt;
  
          &lt;!-- Have a title --&gt;
          &lt;h1 id="welcome"&gt;Read All About It&lt;/h1&gt;
  
          &lt;!-- OK this is a section which will loop round for every item in $news (passed in through from PHP) --&gt;
  {section name=storeShop loop=$storeShop}
     &lt;!-- For every item, display the Title --&gt;
    &lt;h2 id="{$storeShop[$storeShop].id}"&gt;{$storeShop[storeShop].product_name}&lt;/h2&gt;
    &lt;!-- Write out the Author information and the date --&gt;
    &lt;h3&gt;{$storeShop[storeShop].price}, {$storeShop[storeShop].details}&lt;/h3&gt;
    &lt;!-- Now show the news article --&gt;
    {$storeShop[storeShop].details}
  {/section}
      &lt;/div&gt;
  
      &lt;!-- Show copyright information etc --&gt;
      &lt;div id="footer"&gt;All Contents Copy Written :)&lt;/div&gt;
  
    &lt;!-- Close the html tags --&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>when I run the <code>index.php</code> in my browser, I get the following error:</p>
  
  <pre><code>Query failed : Table 'mrshoppc_mainly.$storeShop' doesn't exist
  </code></pre>
  
  <p>But when I use the following code, I get the right output which is the <code>name of the subdomain</code> and the <code>name of the table in mysql database</code> as well:</p>
  
  <pre><code>$storeShop = isSubdomain();
  echo $storeShop;
  </code></pre>
  
  <p>and I know the table exist. P.S. the table name <code>$storeShop</code> is dynamic, so it could be any name that user chooses and it will be created in the mysql database. </p>
  
  <p>I hope I explained it good enough for someone to be able to help me. </p>
  
  <p>Could someone please tell me why I get the mentioned error and how to solve it?</p>
  
  <p>I suspect this is caused by smarty as I never used to get this error before I started using smarty.</p>
  
  <p>Thanks in advance. </p>