「MySQL入門」RAND()でランダムなデータを作成する方法

方法1
SELECT *
FROM changfatbl AS r1 JOIN
(SELECT ROUND(RAND() *
(SELECT MAX(id)
FROM changfatbl)) AS id)
AS r2
WHERE r1.id >= r2.id
ORDER BY r1.id ASC
LIMIT 5;

方法2
SELECT t1.id
FROM producttbl AS t1 JOIN
(SELECT ROUND(RAND() *
((SELECT MAX(id) FROM itemstbl)-(SELECT MIN(id) FROM itemstbl))+
(SELECT MIN(id) FROM itemstbl)) AS id) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id LIMIT 0,5;

「PHP入門」グローバル変数(global variable)を取得するコード

PHPコード:
function globalClearFunc($global_array, $arg, $specialchars = true, $default = null) {
if(key_exists($arg, $global_array) && $global_array[$arg] != null && $global_array[$arg] != “”) {
if($specialchars) {
return htmlspecialchars($global_array[$arg]);
} else {
return $global_array[$arg];
}
} else {
return $default;
}
}

PHPに元のページに戻る方法

方法1
header(‘Cache-control: private, must-revalidate’);

方法2
session_cache_limiter(‘private, must-revalidate’);

「PHP開発」PHPExcelクラスでexcelデータを取得するコード

PHPコード:
require __DIR__ . ‘./PHPExcel/IOFactory.php’;
$PHPReader = new \PHPExcel_Reader_Excel2007();

if (!$PHPReader->canRead($filePath)) {
$PHPReader = new \PHPExcel_Reader_Excel5();

if (!$PHPReader->canRead($filePath)) {
echo ‘no Excel’;
return false;
}
}

$PHPExcel = $PHPReader->load($filePath);

$currentSheet = $PHPExcel->getSheet(0);
$allColumn = $currentSheet->getHighestColumn();

$allRow = $currentSheet->getHighestRow();

for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {

for ($currentColumn = ‘A’; $currentColumn <= $allColumn; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow(ord($currentColumn) – 65, $currentRow)->getValue();
$date[$currentRow – 1][] = $val;
}

}
return $date;

キャッシュを制御するためJavaScript(CSS)ファイルの末尾に「?version=xx」を追加する

サンプルコード
<script type=”text/javascript” src=”demo.js?version=20170422″></script>
<link rel=”stylesheet” type=”text/css” href=”demo.css?version=20170422″ media=”screen,print” />

「java」BufferedReaderを使ってテキストを読むコード

Javaコード:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class FileUtilOperate {

public void readLinesFromFile(String filename) {
BufferedReader br = null;
try {
// BufferedReaderオブジェクト作成
br = new BufferedReader(new FileReader(filename));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {

// BufferedReader閉じる
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

}

public static void main(String[] args) {
FileUtilOperate util = new FileUtilOperate();
util.readLinesFromFile(“startnewsdemo.txt”);

}

}

「Java」BeanUtils.copyPropertiesの使い方

Javaコード:
Product srcProduct = new Product();
srcProduct.setName(“iphone 7”);
Product destProduct = new Product();
PropertyUtils.copyProperties(destProduct, srcProduct);
System.out.println(destProduct.getName());

Redhat6.5にgccをインストールする手順

操作手順
#rpm -ivh mpfr-2.4.1-6.el6.x86_64.rpm
#rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm
#rpm -ivh cpp-4.4.7-4.el6.x86_64.rpm
#rpm -ivh cloog-ppl-0.15.7-1.2.el6.x86_64.rpm
#rpm -ivh gcc-4.4.7-4.el6.x86_64.rpm

「Java」文字列のエスケープ処理コード

Javaコード:
public static String escape(String target) {
if (target == null) {
return “”;
}
String afterEscape = target.replace(“&”, “&amp;”).replace(“\””, “&quot;”).replace(“<“, “&lt;”)
.replace(“>”, “&gt;”).replace(“‘”, “&#39;”);
return afterEscape;
}
}

「java開発」System.getProperty(“line.separator”)の使い方

Javaコード
public String toStrFunc() {
String sptr = System.getProperty(“line.separator”);
StringBuffer sb = new StringBuffer();
for(条件) {
//some code
}
return sb.toString();
}