FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Simple MySQL Template





dafadagod
MySQL Code:
Code:

DROP TABLE IF EXISTS `template`;
CREATE TABLE IF NOT EXISTS `template` (
  `id` smallint(6) unsigned NOT NULL auto_increment,
  `template` mediumtext collate utf8_unicode_ci NOT NULL,
  `title` varchar(100) collate utf8_unicode_ci NOT NULL default '',
  `styleid` smallint(6) NOT NULL default '-1',
  PRIMARY KEY  (`id`),
  KEY `id` (`id`),
  KEY `id_2` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=215 ;

--
-- Dumping data for table `template`
--

INSERT INTO `template` (`id`, `template`, `title`, `styleid`) VALUES (212, '<html>\r\n<head>\r\n<title> example dbtemplate</title>\r\n</head>\r\n', 'part_one', -1);
INSERT INTO `template` (`id`, `template`, `title`, `styleid`) VALUES (213, '<body>\r\nCutted form\r\n<br>', 'part_two', -1);
INSERT INTO `template` (`id`, `template`, `title`, `styleid`) VALUES (214, '\r\n\r\nim footer\r\n</body>\r\n</html>', 'part_three', -1);



Php code:
Code:

<?

Class DBTemplate
{
   var $CacheTemp;
   var $templatecache;
   var $styleid               =   -1;
   var $addtemplatename   =   1;
   var $templatenum         =   1;
   // Database
   var $db_name            =   "database name";
   var $db_hostname         =   "localhost";
   var $db_username         =   "username";
   var $db_password         =   "password";
   
   function DBTemplate ()
   {

   }

   function connect_to_mysql()
   {
      mysql_connect($this->db_hostname,$this->db_username,$this->db_password) or die("cannot connect to mysql server");
      mysql_select_db($this->db_name) or die("cannot select the database name");
   }
   
   function CutForm($templatename,$escape=1,$gethtmlcomments=1)
   {
           if (isset($this->templatecache[$templatename])) {
            $template=$this->templatecache[$templatename];
           } else {

         $ifwher=explode("_",$templatename);
         $ifwhere=$ifwher[0]."_";

              if (!empty($style))
              {
                  $gettempre=mysql_query("SELECT `template`,`title` FROM `template` WHERE `Title` like '$ifwhere%' AND StyleID=".intval($this->styleid)) or die("cannot sellect the query");
              }
              else
              {
                 $gettempre=mysql_query("SELECT `Template`,`Title` FROM `template` WHERE `Title` like '$ifwhere%' AND StyleID=-1");}

         while($gettemp=mysql_fetch_array($gettempre))
              {

            $this->templatenum++;

            $template=$gettemp['Template'];


           if ($escape==1) {
            $template=addslashes($template);
            $template=str_replace("\\'","'",$template);
           }


           if ($gethtmlcomments and $this->addtemplatename) {
            $template = "<!-- BEGIN TEMPLATE: $templatename -->\n $template \n<!-- END TEMPLATE: $templatename -->";
           }
            $this->templatecache[$gettemp['Title']]=$template;
              }
            mysql_free_result();
          }
           return $this->templatecache[$templatename];
         
      }

}

$Temp      =      new DBTemplate;
$Temp->db_name         = "database name";      // test
$Temp->db_hostname   = "database hostname"; // example localhost or domain name.com
$Temp->db_username   =   "database username";   // dafadagod
$Temp->db_password   =   "database password";      // dafapwd
$Temp->connect_to_mysql();
eval("\$index_html_page=\"".$Temp->CutForm("part_one")."\";");
eval("\$index_html_page.=\"".$Temp->CutForm("part_two")."\";");
eval("\$index_html_page.=\"".$Temp->CutForm("part_three")."\";");
echo $index_html_page;

// or
/*

eval("\$header.=\"".$Temp->CutForm("part_one")."\";");
eval("\$body.=\"".$Temp->CutForm("part_two")."\";");
eval("\$footer.=\"".$Temp->CutForm("part_three")."\";");
echo $header.$body.$footer;
*/
?>


example has been included in the php code

8) 8)
Related topics
Fri$ offered for SMF template... simple or complex...
need simple html and css template
Can someone design me simple HTML template? or some images..
//Need a simple flash template// PLEASE LOCK
Site Template FRIH$ available
Simple MySQl Web Site
Web Designing Contest-Need help
Site of my own game server
PHP Tutorials
Please visit my new forum Abundance Blessings Grace Reiki.
PHP/(X)HTML Help
Sava's Guestbook, Free guestbook script
create swishmax Login with phpbb db
FreeFonts (new look)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.