用户名为$ name的Echo $ image

时间:2018-04-05 08:19:14

标签: php html mysql sql database

我必须基于哪个用户登录来回显图像。当用户登录时,代码将检查他的访问级别。基于该访问级别项目将被检索。通过该检索,应该会出现一个链接到该项目的图像。

因此,如果登录用户“测试”,他将获得4个项目,包含4个不同的图像。目前我有这样的链接到文件夹中的图像。但是sporthal.jpg应该替换为变量,以便当有人有权查看学校项目时,他会看到学校项目school.jpg而不是sporthal.jpg

<div class="projecten">
    <table>
        <thead><tr><th>Projecten</th></tr></thead>

        <?php
        $sql="SELECT rechten.Projecten_PrID, rechten.Gebruikers_GID, projecten.naam, projecten.Foto 
              FROM rechten 
              INNER JOIN projecten ON rechten.Projecten_PrID = projecten.PrID 
              WHERE Gebruikers_GID = '".$_SESSION['GID']."'";
        $result = mysqli_query ($conn,$sql) or die("MySQL error: " . mysqli_error($conn) . "<hr>\nQuery: $sql");
        while ($row = mysqli_fetch_array ($result)) {
            echo 
            ' <tbody>
                  <tr>
                      <td>'.$row["naam"].' </a></td>
                      <td>
                          <a href="project.php?" class="knop">
                              <img src="projecten/sporthal.jpg" width="500" height="250" />
                          </a>
                      </td>
                  </tr>
              </tbody>';
        }
        ?>

    </table>
</div>

2 个答案:

答案 0 :(得分:0)

试试这个: 注意:这里我假设projecten.Foto是Image。您已定义某处$imagepath以提供存储图像的完整路径。

<div class="projecten">
    <table>
        <thead><tr><th>Projecten</th></tr></thead>

        <?php
        $sql="SELECT rechten.Projecten_PrID, rechten.Gebruikers_GID, projecten.naam, projecten.Foto 
              FROM rechten 
              INNER JOIN projecten ON rechten.Projecten_PrID = projecten.PrID 
              WHERE Gebruikers_GID = '".$_SESSION['GID']."'";
        $result = mysqli_query ($conn,$sql) or die("MySQL error: " . mysqli_error($conn) . "<hr>\nQuery: $sql");
        while ($row = mysqli_fetch_array ($result)) {
            echo 
            ' <tbody>
                  <tr>
                      <td>'.$row["naam"].' </a></td>
                      <td>
                          <a href="project.php?" class="knop">
                              <img src="'.$imagepath.$row['Foto']." width="500" height="250" />
                          </a>
                      </td>
                  </tr>
              </tbody>';
        }
        ?>

    </table>
</div>

答案 1 :(得分:0)

我已经通过从数据库中删除它并从文件存储器中检索它来解决它:(感谢大家的帮助)

<div class="projecten">
<table>
    <thead><tr><th>Projecten</th></tr></thead>

    <?php
    $imagepath = "projecten/";
    $sql="SELECT rechten.Projecten_PrID, rechten.Gebruikers_GID, projecten.naam, projecten.Foto 
          FROM rechten 
          INNER JOIN projecten ON rechten.Projecten_PrID = projecten.PrID 
          WHERE Gebruikers_GID = '".$_SESSION['GID']."'";
    $result = mysqli_query ($conn,$sql) or die("MySQL error: " . mysqli_error($conn) . "<hr>\nQuery: $sql");
    while ($row = mysqli_fetch_array ($result)) {
        echo 
        ' <tbody>
              <tr>
                  <td>'.$row["naam"].' </a></td> ';

        echo '
                  <td>
                      <a href="project.php?" class="knop">
                          <img src="'.$imagepath.$row["Projecten_PrID"].'.jpg" width="150" height="75" />
                      </a>
                  </td>
              </tr>
          </tbody>';
    }
    ?>
</table>