Re: ACFinder 121218 test2 版 exe のみ

このトピックの投稿一覧へ

なし Re: ACFinder 121218 test2 版 exe のみ

msg# 1.1.1.2.1.1.1.1.1.1.1.1.1.1
depth:
13
前の投稿 - 次の投稿 | 親投稿 - 子投稿なし | 投稿日時 2012.12.21 17:21
OhYeah!  管理人   投稿数: 983 オンライン
携帯農薬検索システムの作物 ID からの上位/下位作物検索クエリー作成ルーチンの抜粋です。
$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' となります。
投票数:0 平均点:0.00

投稿ツリー

  条件検索へ