The next example uses the Bootstrap JavaScript Library when generating the HTML page.

#!c:\ring\bin\ring.exe -cgiLoad"weblib.ring"ImportSystem.WebFuncMainnewBootstrapPage{divstart([:class="container"])divstart([:class="jumbotron"])h1("Bootstrap Page")divend()divstart([:class=:row])divstart([:class="col-sm-4"])h3("Welcome to the Ring programming language")p([:text="Using a scripting language is very fun!"])divend()divstart([:class="col-sm-4"])h3("Welcome to the Ring programming language")p([:text="using a scripting language is very fun!"])divend()divstart([:class="col-sm-4"])h3("Welcome to the Ring programming language")p([:text="using a scripting language is very fun!"])divend()divend()divend()}

The next code presents the Database, ModelBase & ControllerBase classes

ImportSystem.WebClassDatabasecServer="localhost"cUserName="root"cPassword="root"cDatabase="mahdb"FuncConnectcon=mysql_init()mysql_connect(con,cServer,cUserName,cPassWord,cDatabase)FuncDisconnectmysql_close(con)FuncQuerycQuerymysql_query(con,cQuery)FuncQueryResultreturnmysql_result(con)FuncQueryResultWithColumns# return columns names + query resultreturnmysql_result2(con)FuncQueryValueaResult=mysql_result(con)ifislist(aResult)andlen(aResult)>=1aResult=aResult[1]iflen(aResult)>=1returnaResult[1]okokreturn0FuncEscapeStringxifisstring(x)returnMySQL_Escape_String(con,x)elsereturnMySQL_Escape_String(con,string(x))okPrivatecon=NULLClassModelBasefromDatabasecTableName=""cSearchColumn="name"aColumns=[]aQueryResult=[]ID=0# set table name from class nameclassname=lower(classname(self))ifright(classname,5)=:modelcTablename=left(classname,len(classname)-5)okFuncInsertcValues=""forxinaColumnscValues+="'"+EscapeString(aPageVars[x])+"',"NextcValues=left(cValues,len(cValues)-1)# remove last commacColumns=""forxinaColumnscColumns+=x+","nextcColumns=left(cColumns,len(cColumns)-1)query("insert into "+cTableName+"("+cColumns+") values ("+cValues+")")FuncUpdatenIDcStr=""forxinaColumnscStr+=x+" = '"+EscapeString(aPageVars[x])+"' , "# the space after comma is necessaryNextcStr=left(cStr,len(cStr)-2)query("update "+cTableName+" set "+cStr+" where id = "+nID)FuncUpdateColumncColumn,cValuequery("update "+cTableName+" set "+cColumn+" = '"+EscapeString(cValue)+"' where id = "+self.ID)FuncCountcValuequery("SELECT count(*) FROM "+cTableName+" where "+cSearchColumn+" like '"+EscapeString(cValue)+"%'")returnqueryValue()FuncReadnStart,nRecordsPerPagequery("SELECT * FROM "+cTableName+" limit "+EscapeString(nStart)+","+EscapeString(nRecordsPerPage))aQueryResult=queryResult()FuncSearchcValue,nStart,nRecordsPerPagequery("SELECT * FROM "+cTableName+" where "+cSearchColumn+" like '"+EscapeString(cValue)+"%'"+" limit "+EscapeString(nStart)+","+EscapeString(nRecordsPerPage))aQueryResult=queryResult()FuncFindnIDquery("select * from "+cTableName+" where id = "+EscapeString(nID))aResult=queryResult()[1]# move the result from the array to the object attributesID=nIDcCode=""forx=2tolen(aResult)cCode+=aColumns[x-1]+" = hex2str('"+str2hex(aResult[x])+"')"+nlnexteval(cCode)FuncFindWithcColumn,cValuequery("select * from "+cTableName+" where "+cColumn+" = '"+EscapeString(cValue)+"'")aResult=queryResult()iflen(aResult)>0aResult=aResult[1]elsereturn0ok# move the result from the array to the object attributesID=aResult[1]cCode=""forx=2tolen(aResult)cCode+=aColumns[x-1]+" = hex2str('"+str2hex(aResult[x])+"')"+nlnexteval(cCode)return1FuncDeleteIDquery("delete from "+cTableName+" where id = "+EscapeString(ID))FuncClearcCode=""forxinaColumnscCode+=x+' = ""'+nlnexteval(cCode)FuncLoadModel# create the columns arrayquery("SELECT * FROM "+cTableName+" limit 0,1")aQueryResult=QueryResultWithColumns()[1]forx=2tolen(aQueryResult)aColumns+lower(trim(aQueryResult[x]))next# create attribute for each columnforxinaColumnsaddattribute(self,x)nextFuncConnectSuper.Connect()ifnLoadModel=0nLoadModel=1LoadModel()okprivatenLoadModel=0ClassControllerBasenRecordsPerPage=5nRecordsCount=0nPagesCount=0nActivePage=0# Dynamic creation of oView = new tablenameView and oModel = new tablename.Modelclassname=lower(classname(self))ifright(classname,10)=:controllertablename=left(classname,len(classname)-10)cCode="oView = new "+tablename+"View"+nlcCode+="oModel = new "+tablename+"Model"+nleval(cCode)oModel.connect()okcSearchName="searchname"cPart="part"cPageError="The page number is not correct"cLast="last"cOperation="operation"cRecID="recid"aColumnsNames=["id"]fortinoModel.aColumnsaColumnsNames+tnextcMainURL=website+"?"funcRoutingswitchaPageVars[cOperation]onNULLshowtable()on:addaddrecord()on:savesaverecord()on:deletedeleterecord()on:editeditrecord()on:updateupdaterecord()offfuncShowTablenRecordsCount=oModel.Count(aPageVars[cSearchName])nPagesCount=ceil(nRecordsCount/nRecordsPerPage)ifaPageVars[cPart]=cLastaPageVars[cPart]=string(nPagesCount)oknActivePage=number(aPageVars[cPart])ifnActivePage=0nActivePage=1okif(nActivePage>nPagesCount)andnRecordsCount>0ErrorMsg(cPageError)returnoknStart=(nActivePage-1)*nRecordsPerPageifaPageVars[cSearchName]=NULLoModel.Read(nStart,nRecordsPerPage)elseoModel.Search(aPageVars[cSearchName],nStart,nRecordsPerPage)okoView.GridView(self)funcAddRecordoModel.clear()oView.FormViewAdd(Self,:save,false)# false mean don't include record idfuncSaveRecordoModel.Insert()oView.SaveView(self)funcEditRecordoModel.Find(aPageVars[cRecID])oView.FormViewEdit(Self,:update,true)# true mean include record idfuncUpdateRecordoModel.update(aPageVars[cRecID])oView.UpdateView(self)funcDeleteRecordoModel.Delete(aPageVars[cRecID])oView.DeleteView()funcbraceendoModel.Disconnect()