Created
March 4, 2011 21:44
-
-
Save itochan/855752 to your computer and use it in GitHub Desktop.
tiarra検索、Log::DBIで突っ込んだものを検索する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function query_string($query) { | |
return implode("", mysql_fetch_assoc(mysql_query($query))); | |
} | |
$starttime = microtime(true); | |
$db = mysql_connect("localhost", "hagehage", "hogehoge"); | |
mysql_query("SET names utf8"); | |
mysql_query("USE tiarra"); | |
$index = query_string("SELECT count(*) FROM log"); | |
$res = mysql_query("SELECT * FROM channel"); | |
$channel = @$_GET['channel']; | |
$nick = @$_GET['nick']; | |
$query = @$_GET['query']; | |
$channel_list = ""; | |
$hits = "0"; | |
while ($row = mysql_fetch_assoc($res)) { | |
if ($row['id'] == $channel) { | |
$channel_list .= "<option value=\"{$row['id']}\" selected>{$row['name']}</option>\n"; | |
} else { | |
$channel_list .= "<option value=\"{$row['id']}\">{$row['name']}</option>\n"; | |
} | |
} | |
if(isset($query)) { | |
$nickname = "nick_id"; | |
if(!empty($_GET['nick'])) { | |
$res = mysql_query("SELECT id FROM nick WHERE name = '{$nick}'"); | |
$row = mysql_fetch_assoc($res); | |
$nickname = $row['id']; | |
} | |
$res = mysql_query("SELECT * FROM log WHERE channel_id = {$channel} AND nick_id = {$nickname} AND log LIKE '%{$query}%' ORDER BY log.created_on DESC"); | |
while ($row = mysql_fetch_assoc($res)) { | |
$search_res[] = $row; | |
} | |
$hits = count($search_res); | |
} | |
$endtime = round(microtime(true) - $starttime, 3); | |
echo <<< EOF | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>tiarra検索</title> | |
<style> | |
body { | |
font-family: 'Hiragino Kaku Gothic Pro', 'MeiryoKe_PGothic', 'Meiryo', 'MS PGothic',sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<p>tiarra検索</p> | |
<form method="get" action="index.php"> | |
<p>チャンネル: | |
<select name="channel"> | |
{$channel_list} | |
</select><br /> | |
nick: <input type="text" name="nick" value="{$nick}" /><br /> | |
log: <input type="text" name="query" value="{$query}" /><br /> | |
<input type="submit" value="検索" /> | |
</p> | |
</form> | |
<p>{$hits}件({$endtime}s)</p> | |
<hr /> | |
EOF; | |
if (!isset($query)) { | |
} elseif (!isset($search_res)) { | |
echo "見つかりません。"; | |
} else { | |
echo "<table>\n"; | |
echo "<tr><td>nick</td><td width=\"80%\">log</td><td>date</td></tr>\n"; | |
foreach($search_res as $val) { | |
$nickname = query_string("SELECT name FROM nick WHERE id = {$val['nick_id']}"); | |
echo "<tr><td>{$nickname}<td>{$val['log']}</td><td>{$val['created_on']}</td></tr>"; | |
} | |
} | |
echo <<< EOF | |
</table> | |
<hr /> | |
<p>インデックス: {$index}件</p> | |
</body> | |
</html> | |
EOF; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment