how can I give or call the styles css to an html table defined in php?

0
<?php
require('../logica/conexion.php');
 ?>
 <!DOCTYPE html>
 <html lang="es">
 <head>
   <meta charset="UTF-8">
   <title>Comunidad</title>
   <link rel="stylesheet" type="text/css" href="../css/estilos.css">
   <script src="../Jquery/jquery-3.3.1.min.js"></script>
   <script type="text/javascript" src="../js/script.js"> </script>
 </head>
<body>
<h1>Editar</h1>

<?php
$db = new conexion();
error_reporting(E_ERROR | E_WARNING |E_PARSE);
$mensaje=$_GET["mensaje"];

$result=$db->query($mensaje);


if (    $info_campo = mysqli_fetch_fields($result)) {

  $col=mysqli_num_fields($result);
$num=$col-1; ?>
<center>
  <?php
  $table ="<table id=\"tab\" border=\"1px solid #000\" width=\"600\">";

     $table .="<tr>";
        foreach ($info_campo as $valor) {
          $table .= "<th>".$valor->name."</th>";
  }
  $table .= "</tr>";
        $a=0;
       while ($fila=mysqli_fetch_row($result)) {
  $table .="<tr aling=\"center\">";
   for ($i=0; $i <=$num; $i++) {

    $table .= "<td>".$fila[$i]."</td>";
   }
  $a++;
    $table .= "</tr>";
       }

             $table .="</table>";

echo $table;
 }

?>

</body>
</html>
    
asked by Yeko Garcia 30.07.2018 в 01:41
source

1 answer

0

The normal or default way of doing this is to set the css file, in your case estilos.css and at the time of loading the table with php it will use the predefined style. It is a way that works, in fact I use it and the style is applied, even elements loaded with AJAX at the moment also apply the style established in the file.

Therefore my recommendation is as follows:

  • Once the table is loaded, check with your browser's developed tools if the tags are generated correctly in your file
  • Since you have a ID use it:

    #tab{
        border:1px solid red;
    }
    

It would also be possible to add the Style to the table directly in the html but it is advisable to use the other form to have a better organization of the page

    
answered by 30.07.2018 в 10:21