Display image only on those with database data and display name when mouse over image

Asked

Viewed 35 times

0

Good afternoon, I have a list of patients, where displays files through a href giving to visualize them, i want to display an image instead of a "link" (as it is in the picture below) and when I hover over the image, the file name appears. But only in data that has registered files...

I don’t know what to do, I think you should use IF and ELSE...

My table fields: educacao_fisica, enfermagem, nutricao, pedagogia, terapia_ocupacional, servicos_sociais.

PROBLEM: The image appears in all fields, even without having files in this X field.

PRINT

Page code (list_report.php):

<?php

require('conexaobd.php');

$sql = "SELECT * FROM relatorio";

$resultado = mysqli_query($link, $sql);

$inc = 0;



while ($cont = mysqli_fetch_array($resultado)) {

    echo "
        <tr>


                <td>".$cont['paciente']."</td>  

                <td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadsed/".$cont['relatorio_educacao_fisica']."' target='_blank'>".$cont['relatorio_educacao_fisica']."<img src='http://icons.iconarchive.com/icons/zhoolego/material/512/Filetype-Docs-icon.png' style='width:30px; height:30px;cursor:pointer;'></a></td>


                 <td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadsenf/".$cont['relatorio_enfermagem']."' target='_blank'>".$cont['relatorio_enfermagem']."</a></td>

                     <td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadsnut/".$cont['relatorio_nutricao']."' target='_blank'>".$cont['relatorio_nutricao']."</a></td>

                      <td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadsped/".$cont['relatorio_pedagogia']."' target='_blank'>".$cont['relatorio_pedagogia']."</a></td>

                         <td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadster/".$cont['relatorio_terapia_ocupacional']."' target='_blank'>".$cont['relatorio_terapia_ocupacional']."</a></td>

                         <td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadser/".$cont['relatorio_servicos_sociais']."' target='_blank'>".$cont['relatorio_servicos_sociais']."</a></td>

        </tr>
    ";
}

?>

Anybody got any ideas? Thanks.

  • If there is no file, which returns in this variable $cont['relatorio_educacao_fisica'] ?

  • Returns nothing, stays blank

  • And when there is no file, what will be shown?

  • Nothing either '-', Example: https://prnt.sc/qu4q5y

  • Leaving something like ? https://prntscr.com/qu4was

  • That, then when you hover the mouse over a file, display the name of that file, understand?

  • https://prntscr.com/qu4xw8, see if that’s it

Show 3 more comments

1 answer

0


Before creating the column, perform a check if the database information exists any file.

To simplify, the ternary operator was used to carry out the verification.

<?php
echo "
<tr>
    <td>{$cont['paciente']}</td>";

echo $cont['relatorio_educacao_fisica'] != "" ? "<td><a style='color: Blue' href='ver-arquivo.php?documento=uploads/uploadsed/{$cont['relatorio_educacao_fisica']}' title='{$cont['relatorio_educacao_fisica']}' target='_blank'><img src='http://icons.iconarchive.com/icons/zhoolego/material/512/Filetype-Docs-icon.png' style='width:30px; height:30px;cursor:pointer;'></a></td>" : "<td></td>";

/**
 * Adicionar o restando das colunas, relatorio_enfermagem, relatorio_nutricao, ....
 * Lembrando de trocar a pasta também
 */

echo "</tr>";
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.