Re: ACFinder 121218 test2 版 exe のみ
OhYeah!
投稿数: 983
オンライン

携帯農薬検索システムの作物 ID からの上位/下位作物検索クエリー作成ルーチンの抜粋です。
$cid に指定作物の idsaku、$level に指定作物の level を設定しています。指定作物が小分類まで(level <= 2)及び栽培条件付作物名(level == 4)の場合は、指定作物より上位方向のみ検索します。指定作物が作物名(level == 3) の場合は、上位下位全てを検索します。
4行目の _concat は、ACFinder 用 SQLite の拡張 concat 関数と同じ働きをする関数です。たとえば $cid が '0200000000' の場合、3パターンの文字列が全て同じ値になるため、結合結果は '0200000000' となります。
$cid に指定作物の idsaku、$level に指定作物の level を設定しています。指定作物が小分類まで(level <= 2)及び栽培条件付作物名(level == 4)の場合は、指定作物より上位方向のみ検索します。指定作物が作物名(level == 3) の場合は、上位下位全てを検索します。
$cid = $crops[$cno]['idsaku'];
$cid2 = substr($cid, 0, 8);
$level = $crops[$cno]['level'];
$cond = _concat('|', substr($cid, 0, 2)."000000", substr($cid, 0, 4)."0000", substr($cid, 0, 6)."00");
if ($level == 3) $cond = _concat('|', $cond, "{$cid2}");
if ($level == 4) {
$cond = preg_replace("/(~|\|){$cid2}/", '', $cond);
$cond = _concat('|', $cond, "{$cid2}00", $cid);
}
$db = dbOpen();
$except = _concat('|', substr($cid, 0, 4)."000000", substr($cid, 0, 6)."0000", "{$cid2}00");
$sql = "select concat('|', sakumotsu) from sakumotsu where idsaku regexp '$except'";
$res = $db->query($sql);
if (!$res) sqlerror($sql, $db);
$except = $res->fetchColumn(0);
dbCloseStatement($res);
dbClose($db);
$except = '\((.*、)?('.str_replace(array('(', ')', '[', ']'), array('\(?', '\)?', '\[?', '\]?'), $except).')(、.*)?を除く';
$crop = $crops[$cno]['sakumotsu'];
if (strpos($crop, '露地') !== false) $except .= '|施設|水耕';
if (strpos($crop, '施設') !== false) $except .= '|露地';
if (strpos($crop, '水耕') !== false) $except .= '|露地';
$cond = "select sakumotsu from m_sakumotsu where idsaku regexp '^($cond)' and sakumotsu not regexp '$except'";
"{$cid2}00" のように、ダブルクォート内で大括弧({})に囲まれた変数は、変数の値がそのまま文字列展開されます。たとえば、$cid2 の値が '02010013' の場合は、"0201001300" と展開されます。4行目の _concat は、ACFinder 用 SQLite の拡張 concat 関数と同じ働きをする関数です。たとえば $cid が '0200000000' の場合、3パターンの文字列が全て同じ値になるため、結合結果は '0200000000' となります。
投票数:1
平均点:10.00
投稿ツリー
-
ACFinder 121215 test 版 (kabe, 2012.12.15 21:16)
-
Re: ACFinder 121215 test 版 (kabe, 2012.12.16 11:36)
-
ACFinder 121216 test 版 (kabe, 2012.12.16 17:10)
-
Re: ACFinder 121216 test 版 (OhYeah!, 2012.12.16 22:27)
-
Re: ACFinder 121216 test 版 (OhYeah!, 2012.12.17 09:42)
-
Re: ACFinder 121216 test 版 (OhYeah!, 2012.12.17 15:31)
-
-
-
Re: ACFinder 121216 test 版 (kabe, 2012.12.17 14:31)
-
Re: ACFinder 121216 test 版 (OhYeah!, 2012.12.17 21:39)
-
ACFinder 121217 test 版 exe のみ (kabe, 2012.12.17 23:18)
-
Re: ACFinder 121217 test 版 exe のみ (OhYeah!, 2012.12.17 23:51)
-
ACFinder 121218 test 版 exe のみ (kabe, 2012.12.18 07:16)
-
Re: ACFinder 121218 test 版 exe のみ (OhYeah!, 2012.12.18 09:57)
-
Re: ACFinder 121218 test 版 exe のみ (kabe, 2012.12.18 11:15)
-
Re: ACFinder 121218 test 版 exe のみ (OhYeah!, 2012.12.18 17:04)
-
ACFinder 121218 test2 版 exe のみ (kabe, 2012.12.18 22:11)
-
Re: ACFinder 121218 test2 版 exe のみ (OhYeah!, 2012.12.20 14:43)
-
Re: ACFinder 121218 test2 版 exe のみ (OhYeah!, 2012.12.21 17:21)
-
-
-
-
-
-
-
-
-
-
-
-
-