简体   繁体   English

MariaDB:PHP 中的 IF-THEN-ELSE 语句

[英]MariaDB: IF-THEN-ELSE Statement in PHP

Anyone who can help on how to apply MariaDB: IF-THEN-ELSE Statement in PHP.任何可以帮助了解如何应用 MariaDB 的人:PHP 中的 IF-THEN-ELSE 语句。

I want to query when the account type is Admin and he/she created the data in pre_registered table the Cancelled status also display in the list but if he/she is Admin but not the on who created the data it will not display on the list.我想查询帐户类型何时为管理员并且他/她在 pre_registered 表中创建了数据,取消状态也显示在列表中,但如果他/她是管理员而不是创建数据的人,它将不会显示在列表中. If normal user is logged in the system, the Cancelled status will not be included in the list.如果普通用户登录系统,取消状态将不会包含在列表中。

I have try the below query but did not work.我尝试了以下查询,但没有奏效。

<?php
     $account_type = getActiveAccountType($connect);

     $query = "SELECT * FROM pre_registered WHERE ";

    if ($account_type == 'Admin') {
        $query .= "
        
        IF registered_created_by != ".$_SESSION['account_id']." THEN
        {
            registered_status != 'Cancelled'
        }
        END IF;
        
        ";
    } else if ($account_type == 'User') {
        $query .= "
            registered_status != 'Cancelled'
        ";
    }

You want registered_status != 'Cancelled' in regardless of the user type, so include this in $query .无论用户类型如何,您都希望registered_status != 'Cancelled' ,因此将其包含在$query中。

For the admin user, you want to include results with registered_created_by = $account_id .对于 admin 用户,您希望通过registered_created_by = $account_id包含结果。 So in this PHP if branch.所以在这个 PHP if分支中。 Because its an OR condition, it will be included regardless of the registered_status .因为它是一个OR条件,所以无论registered_status是什么,它都会被包含在内。

$query .= ' OR registered_created_by = ?'

When executing this query as a prepared query, pass $_SESSION['account_id'] as the value to be used in the query.当将此查询作为准备好的查询执行时,传递$_SESSION['account_id']作为要在查询中使用的值。

I am new to programming as well, but I hope this helps.我也是编程新手,但我希望这会有所帮助。

Try getting the results first and write a condition that checks if registered_created_by == $_SESSION['account_id'], then show the column if it does and hide if it doesnt.尝试先获取结果并编写一个条件来检查是否已注册_created_by == $_SESSION['account_id'],然后如果有则显示该列,如果没有则隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM