sql 해석... 질문 드립니다.
본문
$str = "";
$exists = false;
$ca_id_len = strlen($ca_id);
$len2 = $ca_id_len + 2;
$len4 = $ca_id_len + 4;
if (!$exists) {
$str = "";
$tmp_ca_id = substr($ca_id, 0, strlen($ca_id)-2);
$tmp_ca_id_len = strlen($tmp_ca_id);
$len2 = $tmp_ca_id_len + 2;
$len4 = $tmp_ca_id_len + 4;
//echo "^*^".$g4[yc4_category_table]; ->yc4_category
// 차차기 분류의 건수를 얻음
$sql = " select count(*) as cnt from $g4[yc4_category_table]
where ca_id like '$tmp_ca_id%'
and ca_use = '1'
and length(ca_id) = $len4 ";
$row = sql_fetch($sql);
$cnt = $row['cnt'];
if (!$cnt)
$str .= "<tr><td width=1 style='border-left:2px solid #9f877b;' ></td><td>";
$sql = " select ca_id, ca_name from $g4[yc4_category_table]
where ca_id like '$tmp_ca_id%'
and ca_use = '1'
and length(ca_id) = $len2 order by ca_id ";
$result = sql_query($sql);
while ($row=sql_fetch_array($result)) {
$style = "";
if ($ca_id == $row[ca_id])
$style = " class='accent' ";
if ($cnt) {
$str .= "<tr><td width=1 bgcolor=#ffffff style='border-right:2px solid #9f877b;'></td>";
$str .= "<td style='padding:2px;'><table width=100% border=0><tr><td width=120> <b> · <a href='#null' onclick='dy_sel1(\"$row[ca_id]\");'><span $style>$row[ca_name]</span></a></b></td>";
$sql2 = " select ca_id, ca_name from $g4[yc4_category_table]
where ca_id like '$row[ca_id]%'
and ca_use = '1'
and length(ca_id) = $len4 order by ca_id ";
$result2 = sql_query($sql2);
$k=0;
while ($row2=sql_fetch_array($result2)) {
if (!$k)
$str .= "<td width=20 align=center>|</td><td class=lh>";
$str .= "<a href='#null' onclick='dy_sel1(\"$row2[ca_id]\");'>$row2[ca_name]</a> ";
$k++;
}
//if (!$k) $str .= "<td></td><td>";
$str .= "</td></tr></table></td><td width=1 style='border-left:2px solid #9f877b'></td>";
} else {
$str .= "<a href='#null' onclick='dy_sel1(\"$row[ca_id]\");'><span $style>$row[ca_name]</span></a> ";
}
$exists = true;
}
if (!$cnt)
$str .= "</td><td width=1 style='border-left:2px solid #9f877b'></td></tr>";
}
솔직히 이 전반적으로 잘 이해가 안됩니다.. 흐름을 잡아주시면 진심으로 감사드립니다 (__)
또한 여기 쓰이는 ca_use는 디비를 열어보면 '1'로 지정이 되어 있는게 그 의미가 무엇이며 tmp_ca_id의 말을 왜 줄여 쓰는지... 또한 그 렝쓰의 의미는 무엇인지 알려주신다면 정말 감사하겠습니다
새해 복 많이 받으시고 늘 건강하십쇼 :)