php - Select last record of each table on database -


i show last record of each table database. tables have same structure ones below:

+------+-----------+------------+--------+-----------+ |  id  |   kh_ho   |   kh_ha    | total  | base_num  | +------+-----------+------------+--------+-----------+ | 1    |   2400    |     2000   | 2569   | 12548     | | 2    |   2600    |     2195   | 2569   | 12548     | | 3    |   2800    |     2400   | 2569   | 12548     | | 4    |   4700    |     4450   | 2569   | 12548     | | 5    |   5200    |     5000   | 2569   | 12548     | | 6    |   4800    |     4795   | 2569   | 12548     | | 7    |   5000    |     4990   | 2569   | 12548     | | 8    |   5800    |     5795   | 2569   | 12548     | | 9    |   7500    |     7950   | 2569   | 12548     | | 10   |   8300    |     8495   | 2569   | 12548     |  

i wanted show last record of each database table , echo kh_ho , kh_ha on last 2 column in table.

can me on using php , mysql?

since last record have highest id ,

 select * `yourtable` `id` = (select max(id)  `yourtable`); 

use can use order clause also

select * `yourtable` order id  desc limit 1; 

for getting table entry

select * `firsttable` `id` = (select max(id)  `firsttable`) union select * `secondtable` `id` = (select max(id)  `secondtable`)  union select * `thirdtable` `id` = (select max(id)  `thirdtable`) . . . union select * `lasttable` `id` = (select max(id)  `lasttable`);           

union ensure same entry listed different table

edit2

<?php    $sql = 'show tables';   $result = mysql_query($sql);   $numofrows = mysql_num_rows($result);      $sqlquery = '';     $i=0;     while($d = mysql_fetch_array($result)){         $i++;          if($i==$numofrows){           $sqlquery .= "select * `".$d[0]."` `id` = (select max(id)  `".$d[0]."`)" ;         }else{           $sqlquery .= "select * `".$d[0]."` `id` = (select max(id)  `".$d[0]."`) union " ;         }     }      echo $sqlquery; //your sql query  ?> 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -