Here is the client part code that allows you to use templates.
For the example use JQuery and JSRender
var clientesRender = function(data) {
if (typeof data === "undefined") {
data = [{
nombre: 'Jorge',
telefono: '3057075510'
}];
}
$("#container").html($("#templateClientes").render({
detalle: data
}));
};
clientesRender();
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsrender/0.9.84/jsrender.min.js"></script>
</head>
<body>
<div id="container"></div>
<script id="templateClientes" type="text/x-jsrender">
<table>
{{for detalle}}
<tr>
<td>
{{:nombre}}
</td>
</tr>
<tr>
<td>
{{:telefono}}
</td>
</tr>
{{/for}}
</table>
</script>
</body>
</html>
For the server part you implement a project like Codeigniter (a very simple MVC to start) or simply create the scripts that return the data in JSON format;
Here is an example script in php:
sql = "SQL" //ejemplo frutería: SELECT id_fruta,nombre_fruta,cantidad FROM tabla_fruta;
function connectDB(){
$server = "SERVER";
$user = "USER";
$pass = "PASS";
$bd = "BD";
$conexion = mysqli_connect($server, $user, $pass,$bd);
if($conexion){
echo 'La conexion de la base de datos se ha hecho satisfactoriamente
';
}else{
echo 'Ha sucedido un error inexperado en la conexion de la base de datos
';
}
return $conexion;
}
function disconnectDB($conexion){
$close = mysqli_close($conexion);
if($close){
echo 'La desconexion de la base de datos se ha hecho satisfactoriamente
';
}else{
echo 'Ha sucedido un error inexperado en la desconexion de la base de datos
';
}
return $close;
}
function getArraySQL($sql){
//Creamos la conexión con la función anterior
$conexion = connectDB();
//generamos la consulta
mysqli_set_charset($conexion, "utf8"); //formato de datos utf8
if(!$result = mysqli_query($conexion, $sql)) die(); //si la conexión cancelar programa
$rawdata = array(); //creamos un array
//guardamos en un array multidimensional todos los datos de la consulta
$i=0;
while($row = mysqli_fetch_array($result))
{
$rawdata[$i] = $row;
$i++;
}
disconnectDB($conexion); //desconectamos la base de datos
return $rawdata; //devolvemos el array
}
$myArray = getArraySQL($sql);
echo json_encode($myArray);
?>
Reviewing this information you can do what you want.
Greetings,