Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old January 16th, 2003, 11:21 PM
disc disc is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Taos,NM,USA
Posts: 17 disc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to disc
Date input and format results

So I have these nifty I frames in this new site we built. Utilising my new2 found PHP skills, I used all the great things I learned here, and diddnt need to su-out the project. THANKS GUYS!

Suddenly a problem. The Iframes have dynamic data culled from MYSQL db. There are currently only 2 feilds: title, description

They update these news items via a nifty backend admin utility. Here is the problem. Right now the dynamic data loads in the order it was input into the database. They want me to add another feild so they can assign a date to each new row, and then have the items load in the order of the asiigned event date, regardless of when it was input.

It seemed like it was simple, but Obviously I am not thinking about it right. Can someone get me on the right track?

Reply With Quote
  #2  
Old January 28th, 2003, 08:35 AM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Date input and format results

Well, this is very simple, the only tricky part is making sure that the date is in the right format...

First, add a datetime field to your table:

ALTER TABLE tablename ADD thetime DATETIME NOT NULL;

Next, you'll probably want to set the dates of current entries to now, so you won't get weird results

UPDATE TABLE SET thetime=NOW()

And you'll also want to add an index, so queries will be faster

ALTER TABLE tablename ADD KEY(thetime)

Finally, you'll need to include an input field for the admins to enter the date. Simplest is just using <input type=text>, although it's not very safe - it's easy to input in a wrong format. Nonetheless:
php Code:
Original - php Code
  1.  
  2. <?php
  3. echo "Please enter a date in format YYYY-MM-DD HH:MM:SS: ";
  4. echo "<input name=thedate type=text maxlength=21 value="".date("Y-m-d H:i:s")."">";


Another option is providing multiple <select> fields, so it's harder to enter an invalid date...

php Code:
Original - php Code
  1.  
  2. <?php
  3. echo "<select name=date_year>";
  4. for ($year=2003; $year<=date("Y"); $year++)
  5.     echo "<option value=$year>$year";
  6. echo "</select>";
  7.  
  8. // similar for month, day, hour, minute, second (or skip some)
  9.  


Then, you can combine them into a valid MySQL date format:
php Code:
Original - php Code
  1.  
  2. <?php
  3. $thedate=$_REQUEST["date_year"]."-".$_REQUEST["date_month"]...;
  4. ?>


Finally, you need to include it in your INSERT query:
php Code:
Original - php Code
  1.  
  2. <?php
  3. $sql="INSERT INTO tablename(something,thedate) VALUES(somethingelse,$thedate)";
  4. ?>


Hope that helped..

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Date input and format results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway