Kohana 3.2 - i want to get distinct dates

Go To StackoverFlow.com


so i have a table with the following:

  1. id
  2. transaction_timestamp (TIMESTAMP CURRENT_TIMESTAMP)

i would like to get distinct dates from the transaction timestamp using Kohana ORM i have a Model named Model_Transactions

if i do this


i get all data. how would i get only the distinct dates since i would use it as an archive. i dont want the user to click on an archive and returns a blank table.

for example: user clicks "April 01, 2012" since there is no transaction on April 01, there is a blank table, i would like to avoid those scenarios, how?

2012-04-03 22:53
by Gian Crescini Santillan


ORM models should represent a single entry in your table. Using the ORM find_all() it will want to select all attributes in the table. Since your id should be unique, each row is essentially distinct.

If you are just wanting to get a list of the distinct transaction_timestamp values, you could add a method to your model to retrieve just that. Something like:

public function get_distinct_timestamps()
    return DB::select('transaction_timestamp')

Then you can use:

$timestamps = Model::factory('transactions')->get_distinct_timestamps();
foreach($timestamps as $timestamp)
    $value = $timestamp['transaction_timestamp'];

Of course this is just an example. You might not want to return an array. But you are not limited to using the ORM query methods.

Another option to get ORM objects with distinct transaction_timestamp is to:

2012-04-04 00:16
by user449954