gpt4 book ai didi

php - 检索多个数据以 ListView ?

转载 作者:搜寻专家 更新时间:2023-10-30 20:35:06 24 4
gpt4 key购买 nike

我正在尝试从多行中检索多个数据...我找到了这段代码并得到了一些我不理解的结果。任何人都可以检查并告诉我它是否正确,稍后我想将这些多个结果显示到 android 应用程序内的 ListView 中......它是否也正确?

为了测试,我使用 postman 运行这段代码并得到这个结果 Screen Shot

在这里你可以查看我的 php 代码:

我的 DbOperations.php

public function gettestuser($pin, $a, $b, $ho, $ll, $c, $d){
$stmt = $this->con->prepare("SELECT * FROM test_category WHERE name = ? AND a = ? Or b = ? Or ho = ? Or ll = ? Or c = ? Or d = ?");
$stmt->bind_param("sssssss",$pin,$a,$b,$ho,$ll,$c,$d);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}

我的gettestuser.php

<?php
require_once '../include/DbOperations.php';

$response = array();

if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_POST['reg_pin'])){

$db = new DbOperations();

$test_category = $db->gettestuser($_POST['reg_pin'], $_POST['reg_a'], $_POST['reg_b'], $_POST['reg_ho'], $_POST['reg_ll'], $_POST['reg_c'], $_POST['reg_d']);

var_dump($test_category);

$response['error'] = false;
$response['pid'] = $test_category['pid'];
$response['name'] = $test_category['name'];
$response['pin'] = $test_category['pin'];
$response['a'] = $test_category['a'];
$response['b'] = $test_category['b'];
$response['ho'] = $test_category['ho'];
$response['ll'] = $test_category['ll'];
$response['c'] = $test_category['c'];
$response['d'] = $test_category['d'];

}else{
$response['error'] = true;
$response['message'] = "Required fields are missing";
}
}

echo json_encode($response);
?>

最佳答案

评论太长了。

这是一个使用括号的查询示例...

SELECT * 
FROM test_category
WHERE name = ?
AND (a = ? Or b = ?)
OR (ho = ? Or ll = ?)
OR (c = ? Or d = ?);

关于php - 检索多个数据以 ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43973291/

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