PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ddragas
Forum Contributor
Posts: 445 Joined: Sun Apr 18, 2004 4:01 pm
Post
by ddragas » Wed Dec 07, 2005 7:09 am
$datum = time();
All entries in db in field 'date' are inserted with value of $datum at the time of inserting into db
Is folowing code correct to search db in column 'date' where 'date' = '21.10.2005'
Code: Select all
$datum = $_POST['pojam'];
include("../stranice/con_db.php");
$result = mysql_query("select * from $table_name where
date = date("d.m.Y ", $datum)") or
die (mysql_error());
while($row = mysql_fetch_array($result))
{
etc......
foobar
Forum Regular
Posts: 613 Joined: Wed Sep 28, 2005 10:08 am
Post
by foobar » Wed Dec 07, 2005 7:15 am
You have a syntax error there, and a semantic error.
This:
Code: Select all
mysql_query("select * from $table_name where date = date("d.m.Y ", $datum)")
should be:
Code: Select all
mysql_query("select * from $table_name where date = '".date("d.m.Y ", $datum)."'")
Assuming your date field is of type text, blob or varchar.
ddragas
Forum Contributor
Posts: 445 Joined: Sun Apr 18, 2004 4:01 pm
Post
by ddragas » Wed Dec 07, 2005 7:24 am
THANK YOU
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Dec 07, 2005 1:05 pm
I don't understand why people don't just use timestamps in databases... ??
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Dec 07, 2005 1:59 pm
The Ninja Space Goat wrote: I don't understand why people don't just use timestamps in databases... ??
Or the databases own DATE field type - makes calculations and formatting of dates
much easier.
Mac
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Wed Dec 07, 2005 3:45 pm
DATE or DATETIME fields are the way to go...
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Dec 07, 2005 4:00 pm
the only advantage date/datetime has over a timestamp in my opinion is that they are human-readable if you are looking at them in phpmyadmin or something.