gpt4 book ai didi

php - 提取具有相同ID的多行mysql php

转载 作者:行者123 更新时间:2023-12-01 00:41:52 26 4
gpt4 key购买 nike

您好,我有下表:

id  request_id  ein intervention_date   time_slot
10 1 600545383 18/05/2015 00:00 AM
11 3 802877145 01/06/2015 00:00 AM
12 3 802310154 02/06/2015 00:00 PM
13 3 801777170 03/06/2015 00:00 AM

我有以下查询:

function get_coach_request_assignment_on_request_id($request_id){
$connection = get_db();
$query = 'SELECT * FROM coach_request_assignment WHERE request_id='.$request_id;
return $connection->query($query);
}

当我调用这个函数时,它只返回第一行,其中request_id=3如何提取查询返回的所有值?

这是我试过的:

$coach_request_assignment_data = get_coach_request_assignment_on_request_id($request_id);
$coach_request_assignment_data = $coach_request_assignment_data->fetch_assoc();

这就是 var_dump($coach_request_assignment_data) 的样子:

array (size=5)
'id' => string '11' (length=2)
'request_id' => string '3' (length=1)
'coach_uin' => string '802877145' (length=9)
'date_intervention' => string '2015-06-01 00:00:00' (length=19)
'time_slot' => string 'AM' (length=2)

在此致谢...

最佳答案

如果这是一个 MySQLi API,那么您将需要多次调用 fetch_assoc() 以获得这些多行。您只调用了一次 ->fetch_assoc():

$results = get_coach_request_assignment_on_request_id($request_id);
$coach_data = array();
while($row = $results->fetch_assoc()) {
$coach_data[] = $row; // push row
}
// print_r($coach_data);

关于php - 提取具有相同ID的多行mysql php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30217959/

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