如何检查数字是否等于某个数字,然后执行(Mysqli)

时间:2019-04-08 10:43:31

标签: php mysql

我的问题是:查询需要检查id = 1,然后显示所有具有该号码的人。对此我还不太陌生,希望我能帮助我。

<?php
include("header.php");
include("checklogin.php");
include('menu.php');

$groep = $_SESSION['groep'];
$naam = $_SESSION['inlognaam'];

$qryGebruikers1="SELECT student.klas_id, gebr.id, gebr.inlognaam, gebr.wachtwoord, rol.naam as rol from gebruiker as gebr
                WHERE studen.klas_id = '1'
                inner join rol on gebr.rol_id=rol.id
                order by gebr.inlognaam;";

$result1=mysqli_query($conn,$qryGebruikers1);

if ($groep == 'verzekering' && $naam == 'verzekering2') 
        {
            echo 'U bent verzekering 2';
        }

(在表中)         |         /


?>


    while  ($row1=mysqli_fetch_array($result1))
    {

        if ($groep == 'verzekering' && $naam == 'verzekering1' )
        {
                    echo '<tr>
                    <td>'.$row1["inlognaam"].'</td>
                    <td>'.$row1["rol"].'</td>
                    <td><a href="changeuser.php?id='.$row1["id"].'&action=edit"><img src="images/edit.png" alt="Wijzigen" style="border: 0px;" /></a></td>
                    <td><a href="changeuser.php?id='.$row1["id"].'&action=delete"><img src="images/drop.png" alt="Verwijderen" style="border: 0px;" /></a></td>
                    </tr>';
        }
    }

?>

我尝试将内部联接和位置切换为

1 个答案:

答案 0 :(得分:0)

首先,您正在访问STUDEN表,但似乎错过了STUDEN表的联接

您可能也需要为此表添加一个JOIN

    SELECT student.klas_id
    , gebr.id
    , gebr.inlognaam
    , gebr.wachtwoord
    , rol.naam as rol 
    from gebruiker as gebr
    inner join rol on gebr.rol_id=rol.id
    INNER JOIN studen ON  stunded.key_col =  table_related.key_col  // <----- this 
    AND studen.klas_id = '1'
    order by gebr.inlognaam;

通常情况下,id是整数,并且如果id是整数,则使用字符串,条件不应该使用引号

   AND studen.klas_id = 1