Show colors in a dropdownlist

0

I have a web application, which has a form for registering new users; Each user is assigned a unique color, taken from the database (MySQL).

I have a user table and a color table. I want that when registering a new user in the option to select a color, show the colors and not the hexadecimal codes of the color (so as they are stored in the BD).

So far I have this:

'<div class="form-row" style="justify-content: center !important;">'+
        '<div class="form-group col-md-11" style="margin-bottom:5px;">'+
            '<label for="ColorName" style="margin: 10px 0px 0px 5px;">Color</label>'+
            '<select class="form-control" name="ColorName">'+
            '<option value="">Seleccione</option>'+
            '<option value=""></option>'+
            <?php
            $Colors = $conexion->query("SELECT * FROM cat_colores AS c WHERE EXISTS (SELECT id_color FROM user WHERE c.id != user.id_color)");
            $cat_colores = $Colors->fetch_all(MYSQLI_ASSOC);
            for ($i=0; $i < count($cat_colores); $i++) {
                echo "'<option value=\"".$cat_colores[$i]['id']."\" style='width:40px;height:20px;background-color:".$cat_colores[$i]['has_color'].">".$cat_colores[$i]['has_color']."</option>'+";
            }
            ?>
        '</select></div>'+
    '<div>'
    
asked by cgasparico 26.12.2018 в 16:47
source

1 answer

0

Solved!

'<div class="form-row" style="justify-content: center !important;">'+
        '<div class="form-group col-md-11" style="margin-bottom:5px;">'+
            '<label for="ColorName" style="margin: 10px 0px 0px 5px;">Color</label>'+
            '<select class="form-control" name="ColorName">'+
            '<option value="">Seleccione</option>'+
            '<option value=""></option>'+
            <?php
            $Colors = $conexion->query("SELECT * FROM cat_colores AS c WHERE EXISTS (SELECT id_color FROM user WHERE c.id != user.id_color)");
            $cat_colores = $Colors->fetch_all(MYSQLI_ASSOC);
            for ($i=0; $i < count($cat_colores); $i++) {
                echo "'<option value=\"".$cat_colores[$i]['id']."\" style=width:40px;height:20px;background-color:".$cat_colores[$i]['has_color']."></option>'+";
            }
            ?>
        '</select></div>'+
    '<div>'

Only move the "\"

    
answered by 26.12.2018 в 17:58