gpt4 book ai didi

php - 在表数组上应用 where 条件

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

我有以下 PHP 文件,我需要将 where 条件添加到 select 语句,条件应如下所示:WHERE tbl_module.delete_time IS NUll数据库中的表以 tbl_ 开头,数组不带 tbl_

$json["status"] = "running";
$details[] = "started get_tables ";
// Include confi.php
include_once('confi.php');
//var_dump($_POST);
$request_body = file_get_contents('php://input');
// first store the given set of data to keep it for future analysis
$statement = "INSERT INTO tbl_archive (content) VALUES ('$request_body' );";
mysql_query($statement);
$input = json_decode($request_body, true);
// now check if valid user
$user = $input["user"];

$username = $user["username"];
$password = $user["password"];

if($password and $username){


$mySQLstring = "SELECT username, password, id FROM tbl_user where username = '$username' ;";
$json["statement"][] = $mySQLstring;
$qur = mysql_query($mySQLstring);
//var_dump ( $qur );
if ($qur){
$res = mysql_fetch_assoc($qur);
}
if ($res){
$json["res"] = $res;
if ($res["password"] == $password){
$json["username"] = $username;
$json["id"] = $res["id"];
$json["status"] = "ok";
$tables = array("class", "class_user", "module", "module_class", "module_user", "rating", "student", "student_class");
//$tables = array("class");
foreach($tables as $table){
$statement = "SELECT * FROM tbl_".{$table};

$qur = mysql_query($statement);
if ($qur){
while($r = mysql_fetch_array($qur, MYSQL_ASSOC)){
//var_dump($r);
//echo (json_encode($r));
$result[$table][] = $r;
}
}
}
$json = array("status" => "ok", "data" => $result);
}
}
}



@mysql_close($conn);

/* Output header */
header('Content-type: application/json');
echo json_encode($json);
?>

最佳答案

您应该查看 Official MySQL Documentation :

SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[MAX_STATEMENT_TIME = N]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[FROM table_references
[PARTITION partition_list]
[WHERE where_condition]

因此 WHERE 条件应该位于 FROM 之后。您应该能够轻松修改 $statement 变量以包含它。

关于php - 在表数组上应用 where 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34168942/

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