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


How to make this code simple?





zimmer
To all good in PHP and mysql. I would ask some favor and if you could help me i am willing to donate my 150 coins for this project. I admit i am just average person when it comes to this script code.

Can someone simplify this code to me?

Code:
CREATE TABLE IF NOT EXISTS `#__nxtchat` (
           `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
           `name` VARCHAR( 30 ) NOT NULL default '',
             `tab` int(5) NOT NULL default 0,
             `seq` int(5) NOT NULL default 0,
           `prompt` VARCHAR( 30 ) NOT NULL default '',
           `value` VARCHAR( 100 ) NOT NULL default '',
           `description` VARCHAR( 200 ) NOT NULL default '',
           `type` VARCHAR( 5 ) NOT NULL default '',
            PRIMARY KEY ( `id` )
) ENGINE=MyISAM DEFAULT CHARSET=utf8;          
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'serverid',0,0,'ServerID','0','Internal Use Only','X' )   
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'title',1,1,'nxtchat Title','nxtchat','The title displayed at the top of your nxtchat Window. Default: nxtchat','T' )
       
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'theme',1,2,'Theme','default','Specifies the predefined display theme for the nxtchat Window. Default: default','L' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'allowed_level',1,3,'Allowed Chatters','0','Specifies who can access the chat window. Default: Everyone','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'redirectPage',1,4,'redirectPage','','Specifies where to redirect users without the required user level (above).  If blank, a simple {No Access} message is displayed. Default: Blank','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'language',1,5,'Language','en_US','The language file to use for the nxtchat display. Default: en-US','L' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'height',1,6,'Window Height','400px','The display height of the nxtchat Window. Default: 400px','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'channels',1,7,'Initial Channels','Joomla!,nxtchat','A comma separated list of initial Channels (chat rooms) for the nxtchat Window to display at startup. Default: Joomla!,nxtchat','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'max_nick_len',1,8,'Max Nickname Length','15','The maximum length of a nxtchat Nickname. Default: 15','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'frozen_nick',1,9,'Freeze Nicknames','0','If ON, users cannot change their Nickname using the /nick command. Default: OFF','B')
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'max_channels',1,10,'Max Channels','10','The maximum number of channel (chat rooms) that can be opened for each user. Default: 10','N' )
         
        INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'max_privmsg',1,11,'Max Private Rooms','5','The maximum number of private message rooms that can be opened for each user. Default: 5','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'isadmin',1,12,'Admin Users','admin','A comma separated list of Joomla usernames for ADMIN access to nxtchat commands','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'admin_password',1,13,'Admin Identify Password','impo55ible','If someone tries to change their nickname to an ADMIN level username, this is the password they must enter to achieve admin status for access to nxtchat commands.  Default: impo55ible','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'time_offset',1,14,'Server Time Offset?','0','Establishes the time difference between the server clock and client clock, in SECONDS.  Default=0','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'name_or_uname',2,1,'Display Joomla Username or Real Name','Username','Whether to display the users Joomla username or real name (from Joomla user record) in the Chat Screen.  Default: Username','L' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'nickmarker',2,2,'Colorize Nicknames','1','If ON, nxtchat Nicknames will be highlighted with colors. Default: ON','B' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'date_format',2,3,'Date Format','m/d/Y','The format to use for the display of dates.  Default: m/d/Y','L' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'time_format',2,4,'Time Format','H:i:s','The format to use for the display of time.  Default: H:i:s','L' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'shownotice',2,5,'Notices to Show','3','Notices to show.  Default: 3.  0-no notices,  1- show nickname changes,  2-show connects/disconnects, 3-show both','L' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'showwhosonline',2,6,'Show Current Users','1','Whether to display the list of ONLINE USERS.  Default: ON','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'showsmileys',2,7,'Show Smiley Graphics','1','Whether to display the available SMILEY graphics.  Default: ON','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'displaytabimage',2,8,'Tab Images','1','Whether to display the tag image for nxtchat channels.  Default ON','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'displaytabclosebutton',2,9,'Tab Close Button','1','Whether to display the CLOSE button on channel tabs.  Default: ON','B' )
       
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'btn_sh_whosonline',2,10,'Online User Button','1','Whether to display the BUTTON that toggles the list of ONLINE USERS.  Default: ON','B' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'btn_sh_smileys',2,11,'Smiley Button','1','Whether to display the BUTTON that toggles the display of SMILEY graphics.  Default: ON','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'startwithsound',2,12,'Sound Notifications','1','Whether to generate sound notifications for nxtchat messages.  Default: ON','B'  )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'display_ping',2,13,'Ping Details','1','Whether to display ping details for nxtchat messages. Default ON','B' )
         
         INSERT INTO `#__jpfchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'clock',2,14,'Show Time','1','Display the Date/Time for each jpFChat message.  Default: ON','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'server_script_url',3,2,'Server Script URL','','Needed if SEF causes internal links to be incorrect','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'timeout',3,3,'Inactive User Timeout','60000','The time nxtchat waits before inactive users are logged out. Default: 60000 (60 seconds)','N' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'max_text_len',3,4,'Max Message Length','400','The maximum length of a single message. Default: 400 (characters)','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'output_encoding',3,5,'Encoding','UTF-8','Character encoding nxtchat should use. Default: UTF-8.','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'refresh_delay',3,6,'Refresh Delay','2000','The initial delay between screen refreshes, dynamically altered during chats based on activity.  Default: 2000 (2 seconds)','N' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'max_msg',3,7,'Max History','20','The maximum number of messages to be preserved in the case of nxtchat window reload. Default: 20','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'max_displayed_lines',3,8,'Max Browser Lines','150','The maximum number of nxtchat lines kept in browser memory. Default: 150','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'noLog',3,9,'Create Logs?','0','Logs are OFF by default.  Logs of your chat sessions can slow down performance','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'noFlood0',3,10,'Flood Control?','1','Flood control is ON by default.  Flood control auto-kicks users who send too much data too quickly.','B' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'noFlood1',3,11,'Flood Character Limit','450','Maximum characters that can be sent within the delay period before a user is auto-kicked.  Default: 450','N' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'noFlood2',3,12,'Flood Message Limit','10','Maximum messages that can be sent within the delay period before a user is auto-kicked. Default: 10','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'noFlood3',3,13,'Flood DELAY period','5','SECONDS within which Flood Control looks for violations.  Default: 5','N' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'censor0',3,14,'Word Filter?','1','The Word Filter is ON by default.  The Word Filter replaces censored words with a special character.','B' )
         
        INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'censor1',3,15,'Words to Filter','shit,******,piss,******,pussy','A comma separated list of the words that nxtchat will watch for and filter out of the display.  ','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'censor2',3,16,'Censor Character','#','The character used to replace the words detected by the word filter. Default: #','T' )
         
          INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'display_PoweredBy',4,2,'Show Powered by nxtchat?','1','Whether to show the Powered by nxtchat line at the bottom of the Chat Window.  NOTE:  You MUST purchase a license from jpfchat.com to turn this option OFF.  Default: ON.','B' )
         
         INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
              VALUES ( 'display_pfc_logo',4,1,'Show phpFreeChat Logo?','1','Whether to display the phpFreeChat logo.  NOTE:  You MUST purchase a SEPARATE license from phpfreechat.net to turn this option OFF.  Default: ON.','B' )
maeglin20
Code:
INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( 'serverid',0,0,'ServerID','0','Internal Use Only','X' ),
                                  ( 'title',1,1,'nxtchat Title','nxtchat','The title displayed at the top of your nxtchat Window. Default: nxtchat','T' ),
                                  ( 'theme',1,2,'Theme','default','Specifies the predefined display theme for the nxtchat Window. Default: default','L' ),
........
........
........
                                  ( 'display_pfc_logo',4,1,'Show phpFreeChat Logo?','1','Whether to display the phpFreeChat logo.  NOTE:  You MUST purchase a SEPARATE license from phpfreechat.net to turn this option OFF.  Default: ON.','B' );
jmraker
Is the program meant to restore from a backup of sql statements, initialize a database table or make a backup of sql statements?

You could use this:

Code:
function dbError($query, $errno, $error){
   die('<font color="#000000"><b>' . $errno . ' - ' . $error . '<br><br>' . $query . '<br><br><small><font color="#ff0000"></font></small><br><br></b></font>');
}

function createTables(){
   $sql = 'CREATE TABLE IF NOT EXISTS `#__nxtchat` (
           `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
           `name` VARCHAR( 30 ) NOT NULL default '',
           `tab` int(5) NOT NULL default 0,
           `seq` int(5) NOT NULL default 0,
           `prompt` VARCHAR( 30 ) NOT NULL default '',
           `value` VARCHAR( 100 ) NOT NULL default '',
           `description` VARCHAR( 200 ) NOT NULL default '',
           `type` VARCHAR( 5 ) NOT NULL default '',
            PRIMARY KEY ( `id` )
) ENGINE=MyISAM DEFAULT CHARSET=utf8';
   mysql_query($sql) or dbError($sql, mysql_errno(), mysql_error());
}

function insertChat($rec){
   if(!isset($rec['tab']))      // Do this if you want to make one or more array items optional
      $rec['tab'] = 0;   // Default value if not in the $rec array
   $sql = 'INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` )
                      VALUES ( "' .
            mysql_real_escape_string($rec['name']) . '","' .
            mysql_real_escape_string($rec['tab']) . '","' .
            mysql_real_escape_string($rec['seq']) . '","'.
            mysql_real_escape_string($rec['prompt']) . '","' .
            mysql_real_escape_string($rec['value']) . '","' .
            mysql_real_escape_string($rec['description']) . '","' .
            mysql_real_escape_string($rec['type']) .
         '")';
   mysql_query($sql) or dbError($sql, mysql_errno(), mysql_error());
}

createTables();
insertChat(array('name'=>'serverid','tab'=>0,'seq'=>0,'prompt'=>'ServerID','value'=>'0',description'=>'Internal Use Only','type'=>'X'));   
insertChat(array('name'=>'title','tab'=>1,'seq'=>1,'prompt'=>'nxtchat Title','value'=>'nxtchat','description'=>'The title displayed at the top of your nxtchat Window. Default: nxtchat','type'=>'T'));     
... repeat ...


If it's to create a backup file the "Insert into" syntax allows for multiple rows to be inserted in one statement. You will want to limit the insert to 500 or so records, continuing with a 2nd INSERT INTO statement. (I posted code that generates a sql formatted database dump a while ago. http://www.frihost.com/forums/vt-129769.html If you want I can post the version that isn't in a class and doesn't use a database class.)
Code:
INSERT INTO `#__nxtchat` ( `name` ,`tab` ,`seq` , `prompt` ,`value` , `description`,`type` ) VALUES
   ( 'serverid',0,0,'ServerID','0','Internal Use Only','X' ),
   ( 'title',1,1,'nxtchat Title','nxtchat','The title displayed at the top of your nxtchat Window. Default: nxtchat','T' ),
   ( 'theme',1,2,'Theme','default','Specifies the predefined display theme for the nxtchat Window. Default: default','L' );
Marcuzzo
@zimmer
what do you want to simplify? it creates a table and populates it.
Related topics
Simple PHP Navigation
Show PHP Code
Mail with PHP (Simple Tutorial)
very simple PHP code to get search query string
A Simple Form Mail in PHP
Simple and Detailed Mail Script
Simple PHP forum code needed!
Simple code to make your web page !
[OFFICIAL] Favourite/Best CMS
[Official]Wii
Thumbnail Generation !
Might Sound Crazy But Ultra simple code For Pinball game
How to code a simple blog using PHP
Hello there, guys :D
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.