Is this an ok way to run index.php From database to-assign $sql = "SELECT `Title`, `Meta_Description`, `Meta_Keywords`, `Content` FROM `Static_Pages` WHERE `File_Name` = '$page';"; $result = mysql_query($sql) or header('Location: index.html'); if (mysql_affected_rows() == 0) { header('Location: index.html'); } $rs = mysql_fetch_array($result); $smarty->assign("page_title","$rs[Title]"); $smarty->assign("meta_description", "$rs[Meta_Description]"); $smarty->assign("meta_keywords", "$rs[Meta_Keywords]"); $smarty->assign("content", "$rs[Content]"); $sql = "SELECT `sitename`, `slogan` FROM `website`;"; $result = mysql_query($sql) or die("MySQL error!"); $rs = mysql_fetch_array($result); $smarty->assign("sitename", "$rs[sitename]"); $smarty->assign("slogan", "$rs[slogan]"); $sql = "SELECT `header_scripts`, `footer_scripts`, `scripts1`, `scripts2`, `scripts3`, `scripts4`, `scripts5`, `scripts6`, `scripts7`, `scripts8`, `scripts9`, `scripts10` FROM `scripts`;"; $result = mysql_query($sql) or die("MySQL error!"); $rs = mysql_fetch_array($result); $smarty->assign("header_scripts", "$rs[header_scripts]"); $smarty->assign("footer_scripts", "$rs[footer_scripts]"); $smarty->assign("scripts1", "$rs[scripts1]"); $smarty->assign("scripts2", "$rs[scripts2]"); $smarty->assign("scripts3", "$rs[scripts3]"); $smarty->assign("scripts4", "$rs[scripts4]"); $smarty->assign("scripts5", "$rs[scripts5]"); $smarty->assign("scripts6", "$rs[scripts6]"); $smarty->assign("scripts7", "$rs[scripts7]"); $smarty->assign("scripts8", "$rs[scripts8]"); $smarty->assign("scripts9", "$rs[scripts9]"); $smarty->assign("scripts10", "$rs[scripts10]"); $sql = "SELECT theme FROM `template`;"; $result = mysql_query($sql) or die("MySQL error!"); $rs = mysql_fetch_array($result); $smarty->assign("theme", "$rs[theme]"); $sql = "SELECT `ad1`, `ad2`, `ad3`, `ad4`, `ad5`, `ad6`, `ad7`, `ad8`, `ad9`, `ad10` FROM advertisements"; $result = mysql_query($sql) or die("MySQL error!"); $rs = mysql_fetch_array($result); $smarty->assign("ad1", "$rs[ad1]"); $smarty->assign("ad2", "$rs[ad2]"); $smarty->assign("ad3", "$rs[ad3]"); $smarty->assign("ad4", "$rs[ad4]"); $smarty->assign("ad5", "$rs[ad5]"); $smarty->assign("ad6", "$rs[ad6]"); $smarty->assign("ad7", "$rs[ad7]"); $smarty->assign("ad8", "$rs[ad8]"); $smarty->assign("ad9", "$rs[ad9]"); $smarty->assign("ad10", "$rs[ad10]"); $smarty->display("header.tpl"); $smarty->display("index.tpl"); $smarty->display("footer.tpl"); ?> PHP:
Hey Again! You can assign arrays to the Smarty templates, for example: $sql = "SELECT `ad1`, `ad2`, `ad3`, `ad4`, `ad5`, `ad6`, `ad7`, `ad8`, `ad9`, `ad10` FROM advertisements"; $result = mysql_query($sql) or die("MySQL error!"); $rs = mysql_fetch_array($result); $smarty->assign("adArray", $rs); Code (markup): It stops all the unneeded assigns, and you can access the array data in the templates.. the crash course has a few examples of accessing/assigning arrays. From memory I believe it's {$adArray.ad1}, {$adArray.ad2} etc.. when using the code above, probably need to double check but I think that would work. I would tend to use a MySQL class to manage the database queries, but I guess there is nothing wrong with writing it out - Just makes it a little harder debugging the code as there is more of it. Have Fun Regards, Steve
Hi Steve actually what I have now for future reference is: $sql = "SELECT * FROM advertisements"; $result = mysql_query($sql) or die("MySQL error!5"); $rs = mysql_fetch_array($result); $smarty->assign($rs); Code (markup): Which returns each result name and gives it the same smarty->assign name.