Wednesday, December 3, 2014

Using include include_once print number 1

If in writing your code in php and you are using the include or include_once and the number 1 is printed also, it means that you are using the echo with the include or include_once statement.

So....

if you have

echo include 'foo.php' or echo include_once 'foo.php', remove the echo so it becomes
include 'foo.php' or include_once 'foo.php'

if you are using the short_open_tags, eg:

<?= include_once 'foo.php'?> or <?= include 'foo.php'?>, remove the echo, in this case its the '=' equal sign so it becomes:

<? include_once 'foo.php'?> or <? include 'foo.php'?>

Sunday, November 30, 2014

codeigniter You did not select a file to upload.

This occurs because the field name is missing from the do_upload function.

if($this->upload->do_upload()){
            $data = array('upload_data' => $this->upload->data());
            echo "
";print_r($data);

            //$this->load->view('upload_success',$data);
        } else {
            $error = array('error' => $this->upload->display_errors());
            echo "
";print_r($error);

            //$this->load->view('file_view', $error);
        }

The above code should be:

if($this->upload->do_upload('flyer')){
            $data = array('upload_data' => $this->upload->data());
            echo "
";print_r($data);

            //$this->load->view('upload_success',$data);
        } else {
            $error = array('error' => $this->upload->display_errors());
            echo "
";print_r($error);

            //$this->load->view('file_view', $error);
        }

Add the name of the file field in the do_upload function.

Wednesday, August 13, 2014

HTML5 mobile app page transition flashes/flickers

To solve the flickering of page transitions using HTML5 in mobile developing, set the page transition to none either in the head of your index file:

$(document).bind("mobileinit", function(){
  $.extend(  $.mobile , {
   defaultPageTransition: 'none'
  }); 
}); or in your javascript file:

$(document).bind( 'pageinit', function(event){
    //set defaults
    $.mobile.defaultPageTransition = "none";
});

Tuesday, July 15, 2014

Show create table sql command

Run this command to show the create table sql command:

SHOW CREATE TABLE ;

Get size of database

You can get the size of a specific database by running this command:

SELECT table_schema "Data Base Name",
SUM( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
SUM( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
WHERE table_schema = "";

If you want to show  the size of all databases on a server, then use this command:

SELECT table_schema "Data Base Name",
SUM( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
SUM( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

Thursday, June 26, 2014

Calculating time left in minutes using Javascript

I was creating a mobile app and had a need to be able to show the available time that is left after the user has set the amount of time they have to do something. The code snippet below is from my class:
setEndTime: function(){
        var start_time = new Date();        
        Tracker.start_time = start_time;
        
        var end_time = new Date( start_time.getTime() + ( parseInt(Guests.available_time)*60000 ) );
        Tracker.end_time = end_time;
    },
    
    calculateAvailableTime: function(){
        var current_time = new Date();        
        var difference = current_time - Tracker.start_time;
        difference /= 1000;
        var time_passed = Math.round(difference / 60 );   
        var time_left = parseInt(Guests.available_time) - time_passed;
        Tracker.time_left = time_left;
        var time_value = ( time_left > 1 ) ? " mins" : " min";
        $("#time_left").html(time_left + time_value);
    },
This is how it works. The user sets the time which is Guests.available_time. Upon clicking the button to set the time available, I call the setEndTime function which uses the Javascript date object to capture the time. I set it globally in another class. I then calculate the end time by using the new Javascript object and adding the time available to it. I multiply by 60000 to convert it to timestamp. To get the time that is left, I used a case to capture the page name and then call the calculateAvailableTime function which takes the current time using the Javascript object and then I calculate the difference by subtracting the start time from it. I divide the difference by 1000 to remove the milliseconds then I divide by 60 to get the minutes. I then subtract it from the time that the user had set to get the time that is left.

Wednesday, June 4, 2014

Removing tables from database with a particular prefix

use the statement below to get a list of tables. you can then copy the statement and execute it. if there are alot of tables, you may have to repeat the process as often as needed. SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = 'database_name' AND table_name LIKE 'myprefix_%'; replace 'database_name' with the name of your database and 'myprefix_' with the prefix that you want to delete.