Welcome Guest, Not a member yet? Register   Sign In
Unixtime stamp
#1

[eluser]Yash[/eluser]
Hi,

I need to sort unixtimestamp stored in database.I'm just using order_by function for sort i.e. not sufficient.

form_unix is helpful...?

any help is appreciated.

I want to get latest entry only.
#2

[eluser]xwero[/eluser]
MAX(datefield) is what you need
#3

[eluser]Yash[/eluser]
not working
Code:
$sql="SELECT * FROM threads WHERE 'dsd_title'=\"".$dddd[$i]['url_title']."\" HAVING max('posted_date')";
                    $query=$this->db->query($sql);
                    foreach ($query->result() as $row)
                    {
                       echo $row->thread_title;
                      
                    }
#4

[eluser]xwero[/eluser]
What if you do
Code:
$sql="SELECT * FROM threads WHERE 'dsd_title'=\"".$dddd[$i]['url_title']."\" AND 'posted_date'= max('posted_date')";

Edit : ok above code results in an error which i could have known.
But if you first do a query for the highest date and then add that value to the actual query. If you have a database that supports subqueries you can do it in one query.
#5

[eluser]Sumon[/eluser]
Would any one of you please explain why the following code will not work whether unixtimestamp data field(posted_date) is integer or long integer.
Code:
$sql="SELECT * FROM threads WHERE 'dsd_title'=\"".$dddd[$i]['url_title']."\" order by posted_date";
$query=$this->db->query($sql);
foreach ($query->result() as $row)
{
  echo $row->thread_title;
}
Sorry if i write something foolish Wink
#6

[eluser]Yash[/eluser]
I want to get latest entry from database.date is factor which decide which entry is latest.It contains now() entry i.e. unix timestamp.

Clear?
#7

[eluser]xwero[/eluser]
Code:
$sql="SELECT * FROM threads WHERE 'dsd_title'=\"".$dddd[$i]['url_title']."\" ORDER BY posted_date DESC limit 1";
#8

[eluser]Yash[/eluser]
Thank you for help

final code
Code:
$this->db->order_by('posted_date','desc');
$this->db->limit(1);
$this->db->where('field_title',$somes[$i]['url_title']);
$query = $this->db->get('thdss');
$thssds = $query->row_array();




Theme © iAndrew 2016 - Forum software by © MyBB