简体   繁体   English

return语句不返回任何内容

[英]return statement doesn't return anything

So basically, I have a function getPayments(). 所以基本上,我有一个函数getPayments()。 This function should execute a query, selecting from multiple tables (with joined). 此函数应执行查询,从多个表(已联接)中选择。 Here is my code 这是我的代码

function getPayments($userid, $schoolyear) {
    $stmt = $this->con->prepare("SELECT tbl_payment.payment_receipt_type AS RType, tbl_payment.payment_receipt_number AS RNumber, tbl_feetype.feetype_name AS FName, tbl_payment.payment_amount AS PAmount, tbl_month.month_date AS MDate, tbl_payment.payment_dateadded AS PAdded 
FROM tbl_payment
  INNER JOIN tbl_student ON tbl_student.student_id = tbl_payment.student_id 
  INNER JOIN tbl_schoolyear ON tbl_schoolyear.schoolyear_id = tbl_payment.schoolyear_id
  INNER JOIN tbl_feetype ON tbl_feetype.feetype_id = tbl_payment.feetype_id 
  INNER JOIN tbl_month ON tbl_month.month_id = tbl_payment.month_id   
  WHERE tbl_payment.schoolyear_id = ? AND tbl_payment.student_id = ? ORDER BY payment_dateadded DESC");

    $stmt->bind_param("ss", $userid, $schoolyear);
    $stmt->execute();
    $stmt->bind_result($RType, $RNumber, $FName, $PAmount, $MDate, $PAdded);

    $payments = array();

    while ($stmt->fetch()) {
        $temp = array();

        $temp['paymenttype'] = $RType;
        $temp['receiptnumber'] = $RNumber;
        $temp['feename'] = $FName;
        $temp['paymentamount'] = $PAmount;
        $temp['monthname'] = $MDate;
        $temp['paymentdate'] = $PAdded;

        array_push($payments, $temp);
    }

    return $payments;
}

In my index.php file: 在我的index.php文件中:

//getting payment details for a user
$app->get('/payment/{id}/{sy}', function (Request $request, Response $response) {
$route = $request->getAttribute('route');
// $userid = $request->getAttribute('id');
$userid = $route->getArgument('id');
$schoolyear = $route->getArgument('sy');
    // $schoolyear = $request->getAttribute('sy');
    $db = new DbOperation();
    $payments = $db->getPayments($userid, $schoolyear);
    $response->getBody()->write(json_encode(array("payments" => $payments)));
});

^ This line of code will take the returned array result from getPayment() function then encode it to json. ^这行代码将从getPayment()函数获取返回的数组结果,然后将其编码为json。

The problem is, after testing my API in Postman, Postman only gives me this result 问题是,在Postman中测试了我的API之后,Postman只给了我这个结果

{"payments":[]} 

Please help me. 请帮我。 Thank you. 谢谢。 (Sorry for my bad english) (对不起,我的英语不好)

Find the answer. 找到答案。 I misplace some variables. 我放错了一些变量。

The line $stmt->bind_param("ss", $userid, $schoolyear); $stmt->bind_param("ss", $userid, $schoolyear); should be written as $stmt->bind_param("ss", $schoolyear, $userid); 应该写为$stmt->bind_param("ss", $schoolyear, $userid); .

Everything is working now. 现在一切正常。 Thank you. 谢谢。 :) :)

This thread is now CLOSED. 现在该线程已关闭。

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

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