Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 10-02-2010, 10:10 PM sql select query
Ultra Talker

Posts: 254
Trades: 0
my question is about sql select order by

i am displaying the value of date variable in a page and in the sql query i have given ORDER BY DESC so that the latest date will appear at the top followed by older in a reverse order following is the code

$date = date("l dS \ F Y h:i:s A");

insert into stats (date) values('$date');

$con = mysql_connect("localhost","username","password");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

$sql="select * from stats ORDER BY date DESC";

$sql_result=mysql_query($sql,$con) or exit("Sql Error ".mysql_error());

$sql_num=mysql_num_rows($sql_result);

while($sql_row=mysql_fetch_array($sql_result))
{
$date_sqlquery=$sql_row["date"];

echo "<p>Date = ".$date_sqlquery."</p>";
}

mysql_close($con);


the field type = varchar(100) in the database

how change i change the sql select query so that i can get the latest date value to be printed in a reverse order along with displaying other fields from the stats table

thanks
sudhakararaog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-02-2010, 10:37 PM Re: sql select query
Novice Talker

Posts: 7
Name: Nguyen Van Thu
Location: Viet Nam
Trades: 0
You should add a field 'time_created' type int store mktime() data. Order by with time_created.
__________________

Please login or register to view this content. Registration is FREE
ngockhoa is offline
Reply With Quote
View Public Profile Visit ngockhoa's homepage!
 
Old 10-02-2010, 10:52 PM Re: sql select query
Ultra Talker

Posts: 254
Trades: 0
i have created a field called date1 and under TYPE from phpmyadmin there are
DATE, DATETIME, TIMESTAMP,TIME,YEAR which of these should i select and i have set the length to 100

in the php the date variable is stored as
$date = date('l jS \of F Y h:i:s A');
sudhakararaog is offline
Reply With Quote
View Public Profile
 
Old 10-05-2010, 01:39 AM Re: sql select query
phpdasan's Avatar
Experienced Talker

Posts: 37
Name: Karthick B
Trades: 0
choose DATETIME in mysql and in PHP

the date format shall be

$date = date("Y:m:d:h:s:i");
__________________
There is no secret ingredient.
phpdasan is offline
Reply With Quote
View Public Profile
 
Old 10-05-2010, 06:41 PM Re: sql select query
Ultra Talker

Posts: 366
Name: Steve
Location: Miami, FL, Earth
Trades: 0
for a created date, it should be a TIMESTAMP, and the DEFAULT should be set to CURRENT_TIMESTAMP (there's an option on phpMyAdmin for that)
__________________
- Steve

President,
Please login or register to view this content. Registration is FREE
smoseley is offline
Reply With Quote
View Public Profile Visit smoseley's homepage!
 
Old 10-06-2010, 04:30 AM Re: sql select query
miki86's Avatar
Extreme Talker

Posts: 185
Location: print_r($serbia);
Trades: 0
In phpmyadmin you also have attributes, and if you set that field to "on update CURRENT_TIMESTAMP", whenever you run a query on that row, timestamp will auto update, otherwise leave it blank.
miki86 is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to sql select query
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47254 seconds with 12 queries