gpt4 book ai didi

php - MYSQL SELECT CASE 带变量

转载 作者:行者123 更新时间:2023-11-29 11:29:37 25 4
gpt4 key购买 nike

嗨,我不知道如何将 SELECT CASE 与变量一起使用来检查变量 $name 是否为空 - 如果应该省略空或 $name='empty'。我不知道如何写这个。任何想法?我的代码:

    $name = $_POST['training_name'];
$training_company = trim($_POST['training_company']);
$training_type = trim($_POST['training_type']);
$training_date = trim($_POST['training_date']);
$training_date_expiring = trim($_POST['training_date_expiring']);
$training_score = trim($_POST['training_score']);
$training_place = trim($_POST['training_place']);
$training_trainer = trim($_POST['training_trainer']);

$score = mysqli_query($con,"SELECT * FROM kursanci WHERE imie_i_nazwisko LIKE '%$name%' OR firma='$training_company' OR rodzaj_szkolenia='$training_type' OR data_ukonczenia_szkolenia='$training_date' OR data_waznosci_szkolenia='$training_date_expiring' OR rezultat_szkolenia='$training_score' OR miejsce_szkolenia='$training_place' OR instruktor_prowadzacy='$training_trainer' ");

最佳答案

您可以使用如下所示的选择案例:

SELECT
id,
action_heading,
CASE
WHEN action_type = 'Income' THEN action_amount
ELSE NULL
END AS income_amt,
CASE
WHEN action_type = 'Expense' THEN action_amount
ELSE NULL
END AS expense_amt

FROM tbl_transaction;

关于php - MYSQL SELECT CASE 带变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37640999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com