I have a query that looks like this: (I insert the date created with the php
date function)
$status = "Active";
//(I cannot use the mysql timestamp function for other reason).
$curdate = date("m/j/Y H:i");
$owner = "not assigned";
@ $db_connect = mysql_connect(" localhost", "$db_userna me", "$db_password") ;
if (!$db_connect)
{
echo "Unable to connect to the database;
exit;
}
mysql_select_db ("$db");
$query = "insert into tickets (user, status, loannum, problem, description,
multiples, ticketnumber, ip, office, submissiontime, ticketowner) values
('$user1', '$status', '$loannum', '$problem', '$description', '$multiples',
'$ticketnumber' , '$ip', '$office', '$curdate', '$owner')";
$result = mysql_query($qu ery);
I need to pull out the last fifty records from the database, so I use this
query:
$order = $order;
if ($order ==""){
$order = "user";
}
mysql_select_db ("$db");
$query = "select * from tickets ORDER by $order";
$result = mysql_query($qu ery);
$num = mysql_num_rows( $result);
if I order the tickets by submission time, it orders the items, but not
correctly. It looks like php treating the submissiontime like integer:
example:
12/1/2003 16:51
12/1/2003 16:58
12/10/2003 12:29
12/10/2003 12:36
12/11/2003 07:10
12/2/2003 09:16
How can I tell php treat the submissiontime field in mysql as a date so it
can be ordered correctly? I need to do this so I can do some maths and some
sorting on the the date.
TIA
Yulia 2 3188
In article <fP************ ********@gigane ws.com>,
"Yulia Yegenov" <yu****@nospam. noadd.ru> wrote: I have a query that looks like this: (I insert the date created with the php date function)
//(I cannot use the mysql timestamp function for other reason). $curdate = date("m/j/Y H:i");
[major snip]
if I order the tickets by submission time, it orders the items, but not correctly. It looks like php treating the submissiontime like integer:
Actually it's MySQL doing that, but you're right about the order.
12/1/2003 16:51
12/1/2003 16:58
12/10/2003 12:29
How can I tell php treat the submissiontime field in mysql as a date so it can be ordered correctly? I need to do this so I can do some maths and some sorting on the the date.
Use date('m/d/Y H:i') instead, so that the day gets zero-padded. This
should get MySQL to sort them the way you need, e.g. 12/01 will come
before 12/10.
Or, you could use a datetime column in the MySQL table (assuming you
aren't already).
hth
--
Bulworth : fu***@fung.arg | My email address is ROT13 encoded, decode to mail
--------------------------|--------------------------------------------------
<http://www.phplabs.com/> | PHP scripts and thousands of webmaster resources!
"Yulia Yegenov" <yu****@nospam. noadd.ru> wrote in
news:fP******** ************@gi ganews.com: I have a query that looks like this: (I insert the date created with the php date function)
$status = "Active";
//(I cannot use the mysql timestamp function for other reason). $curdate = date("m/j/Y H:i"); $owner = "not assigned";
@ $db_connect = mysql_connect(" localhost", "$db_userna me", "$db_password") ; if (!$db_connect) { echo "Unable to connect to the database; exit; } mysql_select_db ("$db"); $query = "insert into tickets (user, status, loannum, problem, description, multiples, ticketnumber, ip, office, submissiontime, ticketowner) values ('$user1', '$status', '$loannum', '$problem', '$description', '$multiples', '$ticketnumber' , '$ip', '$office', '$curdate', '$owner')"; $result = mysql_query($qu ery);
I need to pull out the last fifty records from the database, so I use this query:
$order = $order; if ($order ==""){ $order = "user"; }
mysql_select_db ("$db"); $query = "select * from tickets ORDER by $order"; $result = mysql_query($qu ery); $num = mysql_num_rows( $result);
if I order the tickets by submission time, it orders the items, but not correctly. It looks like php treating the submissiontime like integer: example:
12/1/2003 16:51
12/1/2003 16:58
12/10/2003 12:29
12/10/2003 12:36
12/11/2003 07:10
12/2/2003 09:16 How can I tell php treat the submissiontime field in mysql as a date so it can be ordered correctly? I need to do this so I can do some maths and some sorting on the the date. TIA
Yulia
Or, you might do something like "select * from tickets order by
unix_timestamp( $order) desc limit 50". This would get the newest 50
records. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Albert Ahtenberg |
last post by:
Hi,
I have a database with a date field. And I would like to see the report
grouped by a ceratin month and year, how can I do that without multiple
queries?
Albert Ahtenberg
|
by: Noyb |
last post by:
How do I convert a string into a value I can upload to mysql date field.
Specifically, I have a user select a month, day and year from
drop-downs, then I want them submitted to one date field. Thanks!
Steve.
|
by: Newsscanner |
last post by:
Hello,
In my MySQL database, one of the fields eople have to fill in is "DOB"
(Date of Birth).
I have now managed to begin inserting data into my DB via a form, the
data type for the DOB field is "DATE", but every time I add data and
then check my db, I see the DOB displayed as "0000-00-00".
Has anyone got any idea how I could put this right?
TIA,
|
by: Dan Lewis |
last post by:
I've imported a ms access database into a table in a mysql database.
The access database contains a field that holds date/time values in
'general date' format. These all show up at 01/01/1970 in the mysql
database. I believe the field in mysql is wanting UTC and shows
numbers when looked at from the sql command line (i.e. March 13, 2006,
5:31 pm is shown as 1142289086). How do I get the access data into
that format so it will import...
|
by: hph |
last post by:
Please be gentle; I am a relative newbie for php/MySQL, and most of what
I am doing is based on being self-taught using someone else's
well-written code, and my own googling the answers to my questions.
I'm doing a php/MySQL page that reads data out of a MySQL database.
Longer term, I'll do a data-entry screen allowing me to modify the
database or add new records. For now, I'm just using phpmyadmin to data
enter stuff.
Is there a way...
| |
by: walterbyrd |
last post by:
My MySQL table has a field that is set as type "date." I need to get
today's date, and insert it into that field. The default for that MySQL
field is 2006-00-00.
I know about the date() function. I have tried date("Y-m-d") and
date("U"), neither worked. The date field was just filed with all
zeros.
Can anybody point me in the right direction?
|
by: libsfan01 |
last post by:
how can i use regular expressions to ensure a mysql format date entry
in a text field?
thanks
marc
|
by: Atli |
last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users.
Anyone should be able to get through this without much trouble. Programming knowledge is not required.
Index
What is SQL?
Why MySQL?
Installing MySQL.
Using the MySQL command line interface
|
by: Geoff Cox |
last post by:
Hello,
at the moment I can add the combined date and time into MySQL using
php
$dt1 = date("Y-m-d H:i:s");
is it possible to add the date and time separately?
I thought it might be
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |