Ngocbd

    Select Top Percent Records MSSQL, MySQL

    Returning TOP records Microsoft SQL Server – SELECT TOP 10 column FROM table My SQL – SELECT column FROM table LIMIT 10 Returning TOP PERCENT Records Microsoft SQL Server – SELECT TOP 50 PERCENT * FROM table MySQL – SELECT @percentage := ROUND(COUNT(*) * 50/100) FROM table;   PREPARE STMT FROM ‘SELECT * FROM table LIMIT ?’;  EXECUTE…

    Read More

    Determine The First Day Of Week And The First Day Of Month

    1. Determine the first day of week (Monday) To find Monday of next week, we change ‘last’ to ‘next’. To determine the distance of current day with the first day of week, we use function: <?php echo floor((strtotime (“now”)- strtotime(“last Monday”))/86400); ?> 2. Determine the first day of month <?php $day = date(‘Y-m-d’, strtotime(date(‘Y-m-01’, strtotime(“now”))));…

    Read More

    Limit Download Speed With PHP

    http://code.google.com/p/phptraining/source/browse/trunk/download_limited.php class DownloadLimited { /** * Send the local file to client with limit download rate as user view file name * * @param string $localFile file to send * @param string $userViewFileName filename client will see * @param float $downloadRate download limit speed in kb/s (ex: 50 kb/s) * @return no return */ function…

    Read More

    PHP World – The First Concepts

    Using mature PHP or a particular programming language, the first step you should remember and distinguish between the terms / concepts most basic commonly used in relation to the language itself or enforcement platform of that language. PHP also has a list of terms (simple but easy to ignore as): PHP: PHP Hypertext Preprocesser or Personal…

    Read More

    Short PHP Code

    This is some example of short code in PHP Exp1 : // A lot of code $status = fwrite($h, ‘some text’); if (!$status) { log(‘Writing failed’); } // Less code ${0} = fwrite($h, ‘some text’); if (!${0}) log(‘Writing failed’); // Even less code fwrite($h, ‘some text’) or log(‘Writing failed’); Exp2 : // A lot of…

    Read More

    Helper tinyMCE

    You can refer manual at : http://blog.javamonday.com/2016/06/using-helper-tinymce-in-cakephp-12.html Create file app/views/helpers/tinymce.php with content : <?php class TinyMceHelper extends AppHelper { // Take advantage of other helpers var $helpers = array(‘Javascript’, ‘Form’); // Check if the tiny_mce.js file has been added or not var $_script = false; /** * Adds the tiny_mce.js file and constructs the options *…

    Read More

    Using TinyMCE, iBrowser With CakePHP

    TinyMCE Setup Download TinyMCE in Here After downloaded, extract to TinyMCE folder and copy /tiny_mce folder into /webroot/js in cakePHP. Config Putting this code to layout (or view if you don’t want to use default for all layout) <?php if(isset($javascript)): echo $javascript->link(‘tiny_mce/tiny_mce.js’); endif; ?> Define to use javascript helper in Controller: <script type=”text/javascript”> tinyMCE.init({ theme :…

    Read More