nika nika - 2 months ago 6
PHP Question

how to assign to php variable single value from last row in SQL

I am trying to get the value from last row in SQL and then assign it to php variable

<?php
$get_last_record = "SELECT code FROM table_name ORDER BY id DESC LIMIT 1
?>


So I already got those last row with only value called "code" now how i should assign it to variable ?

Answer

<?php $get_last_record = "SELECT code FROM table_name ORDER BY id DESC LIMIT 1"; $result_query = mysqli_query($reference_to_your_mysqli_connect, $get_last_record); $data_from_query = mysqli_fetch_assoc($result_query); $code = $data_from_query['code']; echo $code; ?>