How to check last row ref by column username using php and mysql? -


how check last row ref column username using php , mysql ?

this table

 _________________________________ |_id_|_____username_____|___val___| |  1 |      aaaa        |    3    | |  2 |      aaaa        |    4    | |  3 |      aaaa        |    5    | |  4 |      cccc        |    1    | |  5 |      cccc        |    3    | |  6 |      cccc        |    4    | |  7 |      cccc        |    7    | |  8 |      dddd        |    2    | |  9 |      dddd        |    4    | 

and code.

<?php include("connect.php"); $strsql = "select * table order id asc "; $objquery = mysql_query($strsql); while($objresult = mysql_fetch_array($objquery)) {     echo ["val"];     echo "<br>"; } ?> 

when test code. i'll echo

3 4 5 1 3 4 7 2 4 

but want echo username in last row this.

3 4 5 aaaaa 1 3 4 7 ccccc 2 4 ddddd 

how can ? thank you.

try this:

select t1.val,t2.username `test` t1 left join (select max(id) id,username `test` group username) t2 on t1.id=t2.id 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

node.js - Express and Redis - If session exists for this user, don't allow access -

excel - I can't get the attachement of the email PHP -