Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 help SQL2005-PHP date select

Author  Topic 

odonel
Starting Member

4 Posts

Posted - 2007-06-25 : 09:05:48
nice site...

i have this table in msql 2005 that i am trying to query from .php

[msg_date] [datetime] NOT NULL which returns 2007-06-25 08:02:55... about 30days of stuffs over 100k rows. I'd would like to select a range to display, for instance (2007-06-21 to 2007-06-24). I tried many approaches discussed in this forum such (datediff,dateadd....), but the queries returned 0 result when tried . How do I proceed...??

here is the query that i am trying to limit the results...
$query = "SELECT msg_date,from_user,msg_text FROM msg WHERE to_user =NULL and from_user !=''";

while($row = mssql_fetch_array($result))
{
echo "<li>" . $row["msg_date"] . "  " . $row["from_user"] . "  " . $row["msg_text"] . "</li>";
}


anyone has done this in .php ??


thank you

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-25 : 09:10:37
Try this query

$query = "SELECT msg_date,from_user,msg_text FROM msg WHERE to_user IS NULL and from_user !=''";

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

odonel
Starting Member

4 Posts

Posted - 2007-06-29 : 07:51:48
thanx for your reply madhi, i have no problem with the statement to_user=null works fine for me in php. I just want to select a date range..e.g if i want to select from the past 3 days, or june 21 to june 25.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-29 : 08:03:30
where datecol>=Dateadd(day,-3,datecol)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

odonel
Starting Member

4 Posts

Posted - 2007-06-29 : 08:32:01
now it returns the whole query

$query = "SELECT msg_date,from_user,msg_text FROM zbc_msg WHERE to_user =NULL and msg_date >= Dateadd(day,-3,msg_date)";

here is part of the return query

Jun 21 2007 3:02PM ggg User entered room
Jun 21 2007 3:02PM ggg ggggggggggggg
Jun 21 2007 3:02PM ggg ffffffffffffff
Jun 21 2007 3:02PM ggg dddddddddddddddddd
Jun 21 2007 3:02PM ggg ssssssssssssssssssss
Jun 21 2007 3:02PM ggg hhhhhhhhhhhhhhhhhhh
Jun 21 2007 3:02PM ggg tttttttttttttttt
Go to Top of Page

odonel
Starting Member

4 Posts

Posted - 2007-06-29 : 08:52:09
madhi, i am trying this approach which seems to give me some positive result

$query = "SELECT msg_date,from_user,msg_text FROM zbc_msg WHERE to_user =NULL and msg_date between '2007-06-21' and '2007-06-23' ";
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-29 : 08:56:39
quote:
Originally posted by odonel

madhi, i am trying this approach which seems to give me some positive result

$query = "SELECT msg_date,from_user,msg_text FROM zbc_msg WHERE to_user =NULL and msg_date between '2007-06-21' and '2007-06-23' ";

Good. Still dont know how to_user=NULL works

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -