如何使用此代码连接sql,html和php

时间:2018-09-18 19:25:18

标签: php html mysql concatenation

基本上,这是一个元素,它显示来自数据库路径的图像。但是我只是无法使其工作。

<img class="img-circle profile_img" id="blah" src=" <?php $query2=mysqli_query($conexao,"select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
    while($row2=mysqli_fetch_array($query2)){
        if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
            echo '<img class="image--cover" id="blah" src="'.$row2['img_local'].'" alt="Avatar" title="DEFINIDA" onerror="this.onerror=null;this.src=1.png;">';
        } else {
            echo 'Show a default image.'; // <img src="path_to_default_image" alt="Default_image"/>
        }
    } ?>" alt="Avatar" title="DEFINIDA" >

1 个答案:

答案 0 :(得分:0)

我设法工作了,最终代码:

<?php
            $query2=mysqli_query($conexao,"select * FROM esc_usuarios_fotos WHERE img_usu_codigo = '" . $_SESSION['codigo'] . "'");
            while($row2=mysqli_fetch_array($query2)){
                if ((!empty($row2['img_local'])) && (file_exists($row2['img_local']))) {
                    echo '<img class="image--profile" src="'.$row2['img_local'].'" title="Clique para abrir seu perfil">';
                } else {
                    echo '<img class="image--profile" src="images/user.png">';
                }
              }
            ?>