0

I want to save the last generated voucher in a variable and used as an input for another query..

$last = $this->db->query('SELECT MAX(voucherno) AS `last` FROM `purchasebill` ORDER BY no DESC LIMIT 1')->row_array();
    $result = $this->db->query("SELECT * FROM `purchaseitem`  where vno= '$last[0]' ORDER BY  vno " )->result_array();

I tried like the above code it gives me an error undefined offset 0..Help me to save the last generated voucher no in an last variable

1 Answer 1

1

As per the document, $last[0] will return entire first row. In your case you want to access the value of MAX(voucherno) which is stored in an alias last.

Change $last[0] to $last['last'] in your next query and it shall work.

"SELECT * FROM `purchaseitem` WHERE vno = '{$last['last']}' ORDER BY vno"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.