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 STMT USING @percentage;

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"))));
return $day;
?>

Or:
<?php
$date = date("01/m/Y");
echo $date;
?>
Good luck!

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 sendFile($localFile,$userViewFileName,$downloadRate)
 {
 /** check file exists
 * @see file_exists
 */
 if(!file_exists($localFile))
 {
 throw new Exception('File not found execption file :'.$localFile.' not found');
}
/** check file is file
* @see is_file
*/
if(!is_file($localFile))
{
 throw new Exception($localFile.' not is a file');
}
if(!is_readable($localFile))
{
 throw new Exception('file '.$localFile.' not readable ');
}
// send headers
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($localFile));
header('Content-Disposition: filename='.$userViewFileName);

// flush header content
flush();
// open file stream
$file = fopen($localFile, "r");
while(!feof($file))
{

 // send the current file part to the browser
 print fread($file, round($downloadRate * 1024));

 // !important flush the content to the browser
 flush();

 // !important sleep one second
 sleep(1);
}

// close file stream
fclose($file);


}
/**
* Send the string data to client with limit download rate as user view file name
*
* @param string string data to send include ascii,utf-8 character
* @param string $userViewFileName filename client will see
* @param float $downloadRate download limit speed in kb/s (ex: 50 kb/s)
* @return no return
*/
function sendString($data,$userViewFileName,$downloadRate)
{
 // send headers
 header('Cache-control: private');
 header('Content-Type: application/octet-stream');
 header('Content-Length: '.strlen($data));
 header('Content-Disposition: filename='.$userViewFileName);
 // flush header content
 flush();

 $start=0;
 $sendSize=0;
 while($sendSize {
 $sendSize=round($downloadRate*1024);
 print substr($data,$start,$sendSize);
 $start=$sendSize;
 // !important flush the content to the browser
 flush();

 // !important sleep one second
 sleep(1);
}
}
}

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 Home Page. Both of concepts are true and both relate to a friendly & powerful script-programming languageRead more

LAMP: is a combination of Linux, Apache, MySQL, PHP. This is said to be common platform and the most efficient execution of programs written in PHP. With Linux Kernel OS (Ubuntu, RedHad, CentOS ...), Apache webserver, MySQL database and PHP (of course). Read more

PhpMyAdmin: is a program use open source to manage and execute MySQL database, run on web-based, ligthweight, fast. Read more

MySQL: relation database open source. Extremely strong and flexible, is used in most of the projects written in PHP and is present in most economic sectors as a data safety cabinet. Read more

IDE: Intergrated Development Environment. Most of us have used at least a certain IDE to write code. Some popular IDE include: Eclipse, Visual Studio, Netbeans, Zend Studio. 

PDT & Eclipse: PDT is a plugin supports writing PHP code is integrated directly into eclipse. Free and open source, it is believed the popular choice and most affordable for PHP programmers. 

serverside-code: code have been compile and run in server. PHP is one of the programming language on server side. 

clientside-code: often written in JavaScript / VBScript, centralized processing operations on the browser without submitting the request to the server.