Add image to my DataTable

0

I adapted a pagination and filtering for a db of the work, but it has a column of images that will be sent from the form, but when I open it I see all the fields well and in the photo just the image path comes to me I have not found how to correct it or a while ago that I'm with it and I just do not see it.

<!DOCTYPE html>
<html lang="es">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link href="css/bootstrap.min.css" rel="stylesheet"/>
        <link href="css/bootstrap-theme.css" rel="stylesheet"/>      
        <link href="css/jquery.dataTables.min.css" rel="stylesheet"/>    
        <script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
        <script src="js/bootstrap.min.js"></script> 
        <script src="js/jquery.dataTables.min.js"></script>             
        <script>
            $(document).ready(function(){
                $('#mitabla').DataTable({
                    "order": [[1, "asc"]],
                    "language":{
                    "lengthMenu": "Mostrar _MENU_ registros por pagina",
                    "info": "Mostrando pagina _PAGE_ de _PAGES_",
                        "infoEmpty": "No hay registros disponibles",
                        "infoFiltered": "(filtrada de _MAX_ registros)",
                        "loadingRecords": "Cargando...",
                        "processing":     "Procesando...",
                        "search": "Buscar:",
                        "zeroRecords":    "No se encontraron registros coincidentes",
                        "paginate": {
                            "next":       "Siguiente",
                            "previous":   "Anterior"
                        },                  
                    },
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "server_process.php",
                }); 
            });

        </script>       
    </head> 
    <body>      
        <div class="container">
            <div class="row">
                <h2 style="text-align:center">Consulta de Checklist</h2>
            </div>          
            <br>            
            <div class="row table-responsive">
                <table class="display" id="mitabla">
                    <thead>
                        <tr>
                            <th>FOLIO</th>
                            <th>FECHA</th>
                            <th>TURNO</th>
                            <th>GUARDIA</th>
                            <th>SERVICIO</th>
                            <th>FOTO</th>
                        </tr>
                    </thead>                    
                    <tbody>                     
                    </tbody>
                </table>
            </div>
        </div>              
    </body>
</html>

I listen to suggestions at your orders

<?php   
    require 'conexion.php';

    /* Nombre de La Tabla */
    $sTabla = "checkvaciado";

    /* Array que contiene los nombres de las columnas de la tabla*/
    $aColumnas = array( 'id', 'fecha', 'turno', 'nombre', 'servicio', 'foto');

    /* columna indexada */
    $sIndexColumn = "id";

    // Paginacion
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
        $sLimit = "LIMIT ".$_GET['iDisplayStart'].", ".$_GET['iDisplayLength'];
    }


    //Ordenacion
    if ( isset( $_GET['iSortCol_0'] ) )
    {
        $sOrder = "ORDER BY  ";
        for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
        {
            if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
            {
                $sOrder .= $aColumnas[ intval( $_GET['iSortCol_'.$i] ) ]."
                ".$_GET['sSortDir_'.$i] .", ";
            }
        }

        $sOrder = substr_replace( $sOrder, "", -2 );
        if ( $sOrder == "ORDER BY" )
        {
            $sOrder = "";
        }
    }

    //Filtracion
    $sWhere = "";
    if ( $_GET['sSearch'] != "" )
    {
        $sWhere = "WHERE (";
        for ( $i=0 ; $i<count($aColumnas) ; $i++ )
        {
            $sWhere .= $aColumnas[$i]." LIKE '%".$_GET['sSearch']."%' OR ";
        }
        $sWhere = substr_replace( $sWhere, "", -3 );
        $sWhere .= ')';
    }

    // Filtrado de columna individual 
    for ( $i=0 ; $i<count($aColumnas) ; $i++ )
    {
        if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
        {
            if ( $sWhere == "" )
            {
                $sWhere = "WHERE ";
            }
            else
            {
                $sWhere .= " AND ";
            }
            $sWhere .= $aColumnas[$i]." LIKE '%".$_GET['sSearch_'.$i]."%' ";
        }
    }


    //Obtener datos para mostrar SQL queries
    $sQuery = "
    SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumnas))."
    FROM   $sTabla
    $sWhere
    $sOrder
    $sLimit
    ";
    $rResult = $mysqli->query($sQuery);

    /* Data set length after filtering */
    $sQuery = "
    SELECT FOUND_ROWS()
    ";
    $rResultFilterTotal = $mysqli->query($sQuery);
    $aResultFilterTotal = $rResultFilterTotal->fetch_array();
    $iFilteredTotal = $aResultFilterTotal[0];

    /* Total data set length */
    $sQuery = "
    SELECT COUNT(".$sIndexColumn.")
    FROM   $sTabla
    ";
    $rResultTotal = $mysqli->query($sQuery);
    $aResultTotal = $rResultTotal->fetch_array();
    $iTotal = $aResultTotal[0];

    /*
        * Output
    */
    $output = array(
    "sEcho" => intval($_GET['sEcho']),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "aaData" => array()
    );

    while ( $aRow = $rResult->fetch_array())
    {
        $row = array();
        for ( $i=0 ; $i<count($aColumnas) ; $i++ )
        {
            if ( $aColumnas[$i] == "version" )
            {
                /* Special output formatting for 'version' column */
                $row[] = ($aRow[ $aColumnas[$i] ]=="0") ? '-' : $aRow[ $aColumnas[$i] ];
            }
            else if ( $aColumnas[$i] != ' ' )
            {
                /* General output */
                $row[] = $aRow[ $aColumnas[$i] ];
            }
        }

        //$row[] = "<td><a href='modificar.php?id=".$aRow['id']."'><span class='glyphicon glyphicon-pencil'></span></a></td>";
    //  $row[] = "<td><a href='#' data-href='eliminar.php?id=".$aRow['id']."' data-toggle='modal' data-target='#confirm-delete'><span class='glyphicon glyphicon-trash'></span></a></td>";

        $output['aaData'][] = $row;
    }
    echo json_encode( $output );
?>
    
asked by Zerge 07.08.2017 в 13:55
source

1 answer

1

I am not an expert but I get the impression that some part of the code is missing, I do not see where you do the query to the DB to retrieve the fields and fill in the table, maybe I am misunderstanding the question, in any case I leave you a I use a code that I made where I create a table and the filling from a DB, which the last field is an image and it is shown as such although in the DB this route (make sure the route is correct)

<div class="tabcontent" style="margin-top: 10px; margin-left: 30px; width: 100%; height: 450px; overflow-y: scroll;" align="center">
                            <table id="tableTest" onclick="doWatch()" style="height: 5%" border="1" class="pure-table" >
                                <thead> <tr height="10px">
                                        <td><a href="manageDB.php?sort=id">Id</a></td>
                                        <td><a href="manageDB.php?sort=code">Code</a></td>
                                        <td><a href="manageDB.php?sort=name">Name</a></td>
                                        <td><a href="manageDB.php?sort=description">Description</a></td>                                            
                                        <td><a href="manageDB.php?sort=image">Image</a></td>
                                    </tr>
                                </thead> 
                                <tbody>

                                    <?php
// Echo variables

                                    $sort = isset($_GET['sort']) ? $_GET['sort'] : 'id';

                                    $conn = connectDB();

                                    $query = "SELECT *,t.id as ID_t, tt.id as ID_tt FROM tests t, test_types tt "
                                            . "where t.id=tt.id";
                                    debug_to_console($query);

                                    $i=0;
                                    $results = mysql_query($query);
                                    debug_to_console(mysql_error());

                                    if (!$results) {

                                    } else {
                                        while ($row = mysql_fetch_array($results)) {
                                            if ($i%2 != 0){
                                                echo "<tr class='pure-table-odd' height='10px'>";
                                            }
                                            else{
                                                echo "<tr height='10px'>";
                                            }
                                            ?>
                                                <td style="width: 5%;" align="center"><?php echo $row['id'] ?></td>
                                                <td style="width: 10%;" align="center"><?php echo $row['code'] ?></td>
                                                <td style="width: 20%;" align="center"><?php echo $row['name'] ?></td>
                                                <td style="width: 20%;" align="center"><?php echo $row['description'] ?></td>
                                                <td style="width: 20%;" align="center"><img id="image" name="image" style="border: 2px solid ; width: 100px; height: 60px;" alt="" src="<?php echo $row['image'] ?>" align="middle"></td>
                                            </tr>
                                            <?php
                                            $i++;
                                        }
                                    }
                                    mysql_close($conn);
                                    ?>
                                </tbody>

                            </table>
                        </div>
    
answered by 07.08.2017 в 14:20