mysql - Get data Mochiweb -


i see tutorial mochiweb here

but use json , mnesia , show data want know there way data , make variable index.html data render .dtl file using mysql

"hello" -> {selected,_col,results} = odbc:sql_query(conn, "select * test_table"), querystringdata = req:parse_qs(), key =proplists:get_value("username", querystringdata,"anonymous"),                         fname=proplists:get_value("value1", querystringdata,"anonymous"),                         lname=proplists:get_value("value2", querystringdata,"anonymous"),                         test=re:run([key], "^[0-9]*$"),                         if key == "anonymous"->                              io:format("wrong");                         true->                             % io:format("true"),                             sendlist=[{x,y,z} || {x,y,z}<-results, x=:=list_to_integer(key)],                             if sendlist/=""->                                 io:format("dupllicate ~p\n",[req]);                             true->                                 odbc:param_query(conn, "insert test_table (id,first_name,last_name) values (?,?,?)",                                 [{sql_integer,[list_to_integer(key)]}, {{sql_varchar, 45},[fname]},{{sql_varchar, 45},[lname]}])                             end                         end,                          % io:format("my name ~p\n",[results]),                         {ok, htmloutput} = hello_dtl:render([{username, results}]),                         req:respond({200, [{"content-type", "text/html"}],                                 htmloutput}); 

i want render variable data hello.dtl using {%for%} {%endfor%}:

<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html>    <head>       <meta http-equiv="content-type" content="text/html; charset=utf-8">       <title>mochiweb tutorial</title>        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" media="screen">       <link rel="stylesheet" type="text/css" href="css/style.css">    </head>    <body>       <div class="container" style="margin-top: 50px">          <div>             <form method="get">                <div class="col-xs-12">                   <h4 class="col-xs-2">id: </h4>                   <div class="col-xs-4">                      <input type="text" name="username" class="form-control ">                   </div>                </div>                <div class="col-xs-12">                   <h4 class="col-xs-2">fname: </h4>                   <div class="col-xs-4">                      <input type="password" name="value1" class="form-control">                   </div>                </div>                <div class="col-xs-12">                   <h4 class="col-xs-2">lname: </h4>                   <div class="col-xs-4">                      <input type="password" name="value2" class="form-control ">                   </div>                </div>                <div class="col-xs-6">                   <input type="submit" class="btn btn-primary pull-right" value="insert">                </div>             </form>             {% key,value1,value2 in username %}                <div class="col-xs-12" name="key">id {{ key }} have name:{{ value1 }} {{value2}}                </div>             {% endfor %}          </div>       </div>     </body> </html> 

i hope guy can show me way


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -