選択するとジャンプするセレクトボックス

<head>に記述

<script type='text/javascript'>
<!--
var target = '';
function jump(){
var url = document.form1.select.options[document.form1.select.selectedIndex].value;
if(url != '' ){
if(target == 'top'){
top.location.href = url;
}
else if(target == 'blank'){
window.open(url, 'window_name');
}
else if(target != ''){
eval('parent.' + target + '.location.href = url');
}
else{
location.href = url;
}
}
}
// -->
</script>

<body>に記述

<form action="#" name="form1">
<select name="select" onChange="jump()">
<option value='hogehoge1.php?id=1'>hogehoge1</option>
<option value='hogehoge1.php?id=2'>hogehoge2</option>
<option value='hogehoge1.php?id=3'>hogehoge3</option>
</select>
</form>

現在のurlを取得する $_SERVER['REQUEST_URI']

ユーザーが選択した結果に基づいて生成されたページにさらに変数をくっつけてリロードする場合

$_SERVER['REQUEST_URI']

で現在の状態のURLを取得できます。
例えば

http://www.hogehoge.org/index.html?option=QrYQZRQVNQsNZN
のページで

$link = $_SERVER['REQUEST_URI'];

としておいて

<a href='" . $link . "&option2=hoge'>

とすると
http://www.hogehoge.org/index.html?option=QrYQZRQVNQsNZN&option2=hoge
へのリンクが作れます。

Posted in PHP

割り算の余りの処理

floor 余りを切り捨てる
ceil 余りを切り上げる
round 四捨五入
$x = 10;
$y = 3;
print floor($x / $y);
print ceil($x / $y);
print round($x / $y);
:実行結果:::

343

round は四捨五入する際の桁数も指定できます

print round($x / $y, 3);
:実行結果:::

3.333

Posted in PHP

my.cnfを設定する

設定の確認↓

mysql> status
--------------
mysql  Ver 14.7 Distrib 4.1.22, for redhat-linux-gnu (x86_64) using readline 4.3
|
|
|
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
|
|
|
--------------

インストール直後の文字コードを見ると”latin1″とかになっているので、
コレをunicodeに変更します。

/etc とかにあるmy.cnfを設定。
それぞれの項目に以下を追加します。

[mysqld]
default-character-set=utf8
skip-character-set-client-handshake
[client]
default-character-set = utf8
[mysqldump]
default-character-set = utf8
[mysql]
default-character-set = utf8

mysqldを再起動。

#service mysqld restart

mysqlを起動して設定を確認すると。。。

mysql> status
--------------
mysql  Ver 14.7 Distrib 4.1.22, for redhat-linux-gnu (x86_64) using readline 4.3
|
|
|
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
|
|
|
mysql>

http://d.hatena.ne.jp/shimonoakio/20080129/1201609465
http://tod.cocolog-nifty.com/diary/2005/12/xamppphpmysql_6279.html