Custom styled file Upload

Monday, September 17, 2012


I know you are here with scratching your head about file upload.Here is lil trick you can do for any kind of style. ;)



Script
---------
put this in your script block.Don't forget  to include jquery script
 jQuery(document).ready(function() {
    $('input[type=file]').each(function(){
   
    var uploadbuttonlabeltext = $(this).attr('title'); //get title attribut for languagesettings
    if(uploadbuttonlabeltext == ''){
    var uploadbuttonlabeltext = 'Browse';
    }
   
    var uploadbutton = '<input type="button" class="new_form_submit1" value="Browse it!" />';
    $(this).wrap('<div class="fileinputs"></div>');
    $(this).addClass('file').css('opacity', 0); //set to invisible
    $(this).parent().append($('<div class="fakefile" />').append($('<input type="text" class="new_form_upload1"/>').attr('id',$(this).attr('id')+'__fake')).append(uploadbutton));
   
    $(this).bind('change', function() {
    $('#'+$(this).attr('id')+'__fake').val($(this).val());;
    });
    $(this).bind('mouseout', function() {
    $('#'+$(this).attr('id')+'__fake').val($(this).val());;
    });
    });
   
    });

css
-----------

input.file {
    height: 28px;
    opacity: 0;
    position: relative;
    text-align: right;
    z-index: 2;
}
div.fakefile {
    left: 0;
    position: absolute;
    top: 0;
    z-index: 1;
}

.new_form_upload1 {
    border: 1px solid #CCCCCC;
    color: #333333;
    font-size: 12px;
    height: 18px;
    margin-right: 10px;
    width: 140px;
}
.new_form_submit1 {
    background: none repeat scroll 0 0 #666666;
    border: medium none;
    color: #FFFFFF;
    font-size: 12px;
    height: 22px;
    text-align: left;
    width: 130px;
}

HTML
-------

<input id="FilesEventLogo" class="new_form_submit1 file" type="file" name="samplejpg">

happy coding

Continue Reading...

MySQL Stored Procedures first step

Saturday, August 25, 2012






Summary: In this tutorial, you will write the first simple stored procedure and invoke it from command line of MySQL.

Writing the first stored procedure

The first stored procedure is very simple. It retrieves all products from products table. First let’s take a look at the stored procedure source code below:
1DELIMITER //
2CREATE PROCEDURE GetAllProducts()
3  BEGIN
4  SELECT *  FROM products;
5  END //
6DELIMITER ;
Let's examine the stored procedure above in a great details:
  • The first command you see is DELIMITER //. This command is not related to the stored procedure. DELIMITER statement in MySQL is used to change the standard delimiter (semicolon) to another. In this case, the delimiter is changed from semicolon(;) to //, so you can have multiple SQL statements inside stored procedure which can be separated by the semicolon. After the END keyword we use delimiter // to show the end of the stored procedure. The last command changes the delimiter back to the standard one (semicolon).
  • In order to create a new stored procedure you use CREATE PROCEDURE statement. After the CREATE PROCEDURE statement you can specify the name of stored procedure. In this case, the stored procedure name is GetAllProducts.
  • Everything inside a pair of keyword BEGIN and END is called store procedure's body. You can write declarative SQL code in the stored procedure's body.
Now we have created a new stored procedure. It is time to know how to invoke in command line of MySQL.

Calling the stored procedure

In order to invoke a stored procedure, we use the following SQL command:
1CALL STORED_PROCEDURE_NAME()
First you use keyword CALL followed by the stored procedure name and a pair of parenthesis. To invoke the stored procedure GetAllProducts, we use the following command:
1CALL GetAllProducts();
If you run the command above you will get all products in the products database table.
In this tutorial, you’ve learned how to change the delimiter by using DELIMITER statement. It allows you to type multiple SQL statements inside a stored procedure. You’ve also learned how to write a simple stored procedure by using CREATE PROCEDURE statement and invoke it from command line using CALL statement.
Continue Reading...