mardi 21 mai 2019

How to get a MySQL Value as a colour in EJS?

I have a table in my nodeJS project that has data with a status. I would like to show this status in red and green. To render the HTML page I use EJS.

I've already tried using an if/else statement, but there I always get the first value of the statement.

MySQL:

SELECT g_id, g_name, g_status FROM games

EJS:

<table class="table table-hover">
            <thead>
                <tr class="table-info">
                    <th>Name</th>
                    <th>Status</th>
                </tr>
            </thead>

        <% if (data) { 
            data.forEach(function(game){ 

            var status = game.g_status;

            if (status = '1') {
                status = 'color-green';
            } else {
                status = 'color-red';
            }
        %>
        <tbody id="myTable">
            <tr>
                <td><a href=<%= g_id %>><%= game.g_name %></td>
                <td><%= status %></td>
            </tr>
        </tbody>
        <% }) %>
        <% } %>
</table>

What's the problem, and how do I get the SQL output to a specific colour?




Aucun commentaire:

Enregistrer un commentaire