1

I have 2 functions in PHP and i want to return a value to one function to another. this is my functions

 public function save_payment_log_data($icasl_number, $exam_session) {

$paylog_av = $this->payment_log_exists($icasl_number, $exam_session);

}


function payment_log_exists($icasl_no, $exam_session) {
        $this->db->where('icasl_no', $icasl_no);
        $this->db->where('exam_session', $exam_session);
        $query = $this->db->get('exm_paymentlog');
        if ($query->num_rows() > 0) {
            $pl = $query->row();
            $pay_id = $pl->paylog_id;
            return $pay_id;
        } else {
            return false;
        }
    }

I want to return $pay_id to the save_payment_log_data() function but in here $pay_id didn't return to that function. I think it's return from the function payment_log_exists() so how can I return $pay_id to the save_payment_log_data() function

12
  • 2
    so what's the actual question? Commented Jun 5, 2017 at 5:19
  • @rtfm question updated. I want to know how to return that value to save_payment_log_data() function Commented Jun 5, 2017 at 5:21
  • 3
    Try var_dump($paylog_av); under $paylog_av = $this->payment_log_exists($icasl_number, $exam_session); and check what is the result. Commented Jun 5, 2017 at 5:22
  • 1
    when you call the payment_log_exists(), you should either get the pay_id or false. print $paylog_av to see whats coming back Commented Jun 5, 2017 at 5:26
  • 1
    Please modify your question to say, why you're not returning $pay_id . That will essentially mean, that query variable returned <=0 or, most possibly 0. So, verify if you have the records in the db for 'exm_paymentLog' Commented Jun 5, 2017 at 5:32

2 Answers 2

2

See this example it's working fine:

function save_payment_log_data() {

$paylog_av = payment_log_exists();

# print the return value
echo $paylog_av;

}

function payment_log_exists() {
        return "Hello";
    }

save_payment_log_data();

You can try to remove public and this form save_payment_log_data(), and call the save_payment_log_data() function where you want.

Sign up to request clarification or add additional context in comments.

Comments

0

your are only assigning a value to the $paylog_av your "save_payment_log_data" function should be:

public function save_payment_log_data($icasl_number, $exam_session) {

$paylog_av = $this->payment_log_exists($icasl_number, $exam_session);
return $paylog_av;

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.