Robots Rule | MindSculpt.net

New media has met its match.

The MindSculpt Design Syndicate focuses on code that works, from CSS, XHTML and JavaScript tips and tutorials to Flash and ActionScript how-to's. Robots not included.

Archive for February 2010


Reformatting MySQL date (yyyy-mm-dd) from a database with PHP

February 19th, 2010 — 10:04am

The following article assumes you have a solid understanding of PHP 4, PHP 5 and MySQL, and skips all basic setup instructions and explanations in effort to provide you with quick, concise information. It also assumes you have a MySQL database setup with a a field called date that is set as type: DATE.

Storing the current date along with new data into a MySQL database table is a piece of cake. Unfortunately there is little-to-no documentation about how to format a stored date using PHP at runtime.

Assuming your database is already set up and you have a table with a field named date of type DATE, your query would look something like this:

  1. <?php
  2. //This assumes you have already connected to your database and that you have created a table called ‘my_table_name’ with fields ‘content’ and ‘date’
  3.  
  4. $my_content = "This is a sweet-ass tutorial.";
  5.  
  6. $query = "INSERT INTO my_table_name (
  7.             content, date
  8.          ) VALUE (
  9.             $my_content, CURDATE()    
  10.          )";
  11. ?>

The native PHP function CURDATE() saves the current month, day and year into your database table’s ‘date’ field in the format yyyy-mm-dd. So now we’ve got our date stored, which is awesome, but chances are we’ll eventually need to retrieve and display that date next to a heading, article or other saved content at runtime, and it’s not in the most widely-used format.

No need for crazy string replacement functions, insane super-nerd loops or anything else that makes your brain hurt. Behold:

  1. <?php
  2.    // reformatting MySQL date from the stored format (yyyy-mm-dd) to (mm-dd-yyyy)
  3.    // set a temp var to store and convert our date/time from the database to a more human, legible format for display
  4.    // you will need to have already retrieved the corresponding date from the database in some other query
  5.  
  6.    $date = date(‘m/d/Y’,strtotime($your_date_value_from_db))
  7.    
  8.    // display the date
  9.    echo "Date of entry: " . $date;
  10. ?>

This echoes Date of entry: Month/Date/Year, which is a much more common and legible way of writing the date. You can replace the slashes with periods, dashes or switch the order of m d Y to get the desired result, and of course assemble and customize your final echoed string as needed.

Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

2 comments » | PHP

AS2 Refresher: Loading External Bitmaps with loadClip()

February 15th, 2010 — 9:05am

The following article assumes you have a solid understanding of Flash AS2 and the Flash interface, and skips all basic Flash setup instructions and explanations in effort to provide you with quick, concise information. It also assumes you have images ready to be loaded into your swf.

The AS2 refresher series aims to consolidate basic, everyday snippets for the most common tasks used by Flash developers working with legacy files. Basic explanations are included in the comments, since after all, who wants to read through a bunch of crap when you are just after the code? Enjoy.

AS2 sendAndLoad with LoadVars Snippet:

  1. // variables
  2. //——————————————————————————————————————————-
  3.  
  4. // create a var to hold the name of the bitmap we want to load
  5. var imageName:String = "image1.jpg";
  6.    
  7. // set a reference to the folder your images are in ›› the slash (images/) is added below when we assemble the path
  8. var imagePath:String = "images";
  9.  
  10. // set a new MovieClipLoader and immediately load the image into a movieclip on the stage named ‘container_mc’
  11. var mcLoader:MovieClipLoader = new MovieClipLoader();
  12.    mcLoader.addListener(this);
  13.    mcLoader.loadClip(imagePath + "/" + imageName, container_mc)
  14.  
  15. // functions
  16. //——————————————————————————————————————————-
  17.  
  18. // when the image has loaded, begin the ad unit animation
  19. function onLoadComplete(mc:MovieClip) {
  20.    
  21.    trace("image loaded from: " + imagePath + "/" + imageName);
  22.    trace("image loaded into: " + mc);
  23.    
  24.    // load has completed, call init() and start the app
  25.    init();
  26. }
  27.  
  28. // called while image is loading ›› insert preloading actions here
  29. function onLoadProgress():Void {
  30.    
  31.    trace("image loading…");
  32. }
  33.  
  34. function init():Void {
  35.    
  36.    // start your app
  37.    
  38.    // for additional progress event listeners associated with loading external bitmaps,
  39.    //    visit: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001381.html   
  40. }
Share this post:
  • Twitter
  • Facebook
  • del.icio.us
  • Digg
  • LinkedIn
  • Reddit
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • Yahoo! Buzz

Comment » | Flash AS2

Back to top