How to display records from database on a webpage table using nodejs and mysql.
Sample, i entered name on a form textbox and when i click the button. all employees who have that name will display on a table in the same webpaga. please help…
NodeJS- express JS and mysql Sir…Sample, I have form that contains text boxes and table. One is lastname, sample, I want to filter or display on the table, employees having last name like the entry in the text box in the same web page after clicking the search button…
<head>
<title>HTML TABLE DATA SEARCH</title>
<style>
table,tr,th,td
{
border: 1px solid black;
}
</style>
</head>
<body>
<center>
<h2><%= title %></h2>
<form action="/searchh" method="POST" top='50%'>
<input type="text" name="valueToSearch" placeholder="Value To Search"><br><br>
<input type="submit" name="searchh" value="Search"><br><br>
<table style='height: 50%; width: 75%; border-collapse: collapse;'>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Action</th>
</tr>
<% users.forEach(function(users){ %>
<tr>
<td><%= users.name %></td>
<td><%= users.email %></td>
<td><%= users.mobile %></td>
<td>
<a href="edit/<%= users.id %>" class="btn btn-sm btn-primary">Edit</a>
<a href="delete/<%= users.id %>" class="btn btn-sm btn-primary">Delete</a>
</td>
</tr>
<% }); %>
</table>
</form>
</body>
//////////////////////////////////////////////
app.get('/filter', (req, res) => {
let sql = "SELECT * FROM users";
let query = connection.query(sql, (err, rows) => {
if(err) throw err;
res.render('user_filter',{
title : 'USER DETAILS',
users: rows
})
})
})
app.post(’/searchh’, (req, res) => {
// let sql = “SELECT * FROM users”;
//let valueToSearch = valueToSearch;
let valueToSearch = {id: null, name: req.body.name, email: req.body.email, mobile: req.body.mobile};
let sql = “SELECT * FROM users
WHERE CONCAT(id
, name
, email
, mobile
) LIKE '%”+valueToSearch+"%’";
// $search_result = filterTable($query);
// connection.query(‘SELECT name FROM song WHERE name LIKE "%’+str.stringPart+’%"’,function(err, rows, fields)
valueToSearch = connection.query(sql, (err, rows) => {
if(err) throw err;
res.render('user_filter',{
title : 'FILTERED USERS',
users: rows
})
})
})