채택완료

특정 문자열 갯수 구하는법 부탁드립니다....

다름이 아니라 회사의 식사, 빵/우유를 주문하는 게시판을 쓰고 있습니다.

제가 프로그램에 대해 잘몰라서 기존에는 계산하기 편하도록

 

Copy
식사여부 <select name='wr_content' class='ed' itemname='wr_content'><option selected="selected" class="form" value=''>: 선택 :</option><option value='1' class="form" <? if($write[wr_content] == "1") echo "selected"; ?>>O</option><option value='0' class="form" <? if($write[wr_content] == "0") echo "selected"; ?>>X</option></select>     빵/우유 <select name='wr_5' class='ed' itemname='wr_5'><option selected="selected" class="form" value=''>: 선택 :</option><option value='1' class="form" <? if($write[wr_5] == "1") echo "selected"; ?>>O</option><option value='0' class="form" <? if($write[wr_5] == "0") echo "selected"; ?>>X</option></td></select>

 

식사 1혹은0    빵/우유도 1혹은0을 기입하도록 처리하여 합산계산을 하였습니다.

그런데 하루에 식사와 빵/우유 2개를 다 주문하는 사람들이 있어

 

   

Copy
식사선택 <select name='wr_content' class='ed' itemname='wr_content' required = "required" /><option selected="selected" class="form" value=''>: 선택 :</option><option value='식사' class="form" <? if($write[wr_content] == "식사") echo "selected"; ?>>식사</option><option value='빵/우유' class="form" <? if($write[wr_content] == "빵/우유") echo "selected"; ?>>빵/우유</option><option value='선택안함' class="form" <? if($write[wr_content] == "선택안함") echo "selected"; ?>>선택안함</option></select>

 

하나만 선택할수 있도록 처리해놓았습니다.

이렇게 수정하고 나니 관리화면에서 계산이 않되는 문제가 있어 도움을 요청드립니다.

이전에는 1과0의 합산으로 처리를 해놓았는데 현재에는 문자열로 wr_content 값이 식사, 빵/우유, 선택않함 3개의 값으로 나오게 되었습니다.



그래서 여쭤보고 싶은 부분이 식사라고 되어 있는 문자열이 5개가 있으면 5라고 표시할수 있도록 처리하고 싶습니다. 초보자라 꼭좀 부탁드리겠습니다.

감사합니다. 아래는 현재 출력되는 소스의 원본파일을 적어드립니다.

 

Copy
<? include_once("./_common.php"); //include_once("$g4[path]/lib/latest.lib.php"); $g4['title'] = "기간별 검색화면"; //include_once("$g4[path]/_head.php"); include_once("$g4[path]/head.sub.php");?><? // 이하 프린트 제어관련 스크립터 ?><script language="javascript">// 인쇄보기/페이지설정/인쇄대화상자/인쇄하기 버튼제어function ieExecWB( intOLEcmd, intOLEparam ){     var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';document.body.insertAdjacentHTML('beforeEnd', WebBrowser);if ( ( ! intOLEparam ) || ( intOLEparam < -1 )  || (intOLEparam > 1 ) )        intOLEparam = 1;        WebBrowser1.ExecWB( intOLEcmd, intOLEparam );        WebBrowser1.outerHTML = "";}</script><script language=javascript>// 인쇄 시작전에 실행되는 함수// 'no'으로 시작하는 div 태그 제거function window.onbeforeprint(){    var divs = document.all.tags("div")    for (i=0;i<divs.length;i++)    {        if (divs[i].id.substring(0,2)== "no") {        divs[i].style.display = "none";        }    }}function window.onafterprint()//인쇄가 종료되면 실행되는 부분//모든 div 태그를 재생{    var divs = document.all.tags("div")    for (i=0;i<divs.length;i++)    {        divs[i].style.display = "inline"    }}</script><? // 페이지 넘김/다음페이지로 ?><STYLE TYPE="text/css">    <!-- .break {page-break-before: always;} --></STYLE><? /*인쇄 버튼 누를 필요없이 자동으로 인쇄.------------------------------<SCRIPT LANGUAGE="JavaScript"><!-- Beginfunction printPage() {window.print();}// print --></script><body OnLoad="printPage()">-------------------------------*/ ?><? // 여기까지 프린터 제어 관련 스크립터 ?> <? // if (!$fr_date)    $fr_date = "00000000"; // 처음부터 검색 if (!$fr_date)    $fr_date =  date("Ymd", time()); if (!$to_date)    $to_date = date("Ymd", time()); if ($sort1 == "") $sort1 = "ca_name";    if ($sort2 == "") $sort2 = "asc"; //desc    $sql  = " select * from g4_write_$bo_table ";  if ($fr_date && $to_date) {  $sql .= " WHERE (wr_1 between '$fr_date' and '$to_date') "; } if ($gubun) { $sql .= " AND ca_name like '$gubun' "; }    if ($gubun2) { $sql .= " AND wr_9 like '$gubun2' "; }   $sql .= " order by $sort1 $sort2 ";  $result = sql_query($sql); $total_count = mysql_num_rows($result); //$rows = $config[cf_page_rows]; $rows = 500; // 한화면에 나올 게시물수 합계를 보기위해 많이잡음.인쇄시 페이지 나눔.    $pagerows    = 50; // 페이지당 인쇄 라인수    $printpage   = ceil($total_count / $pagerows); //인쇄페이지수    $firstpage   =  0; $total_page  = ceil($total_count / $rows);  // 전체 페이지 계산 if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지) $from_record = ($page - 1) * $rows; // 시작 열을 구함 $rank = ($page - 1) * $rows; $sql = $sql . " limit $from_record, $rows "; $result = sql_query($sql); $qstr = "page=$page&sort1=$sort1&sort2=$sort2"; $qstr1 = "fr_date=$fr_date&to_date=$to_date&sel_ca_id=$sel_ca_id";  ?><!-- 테스트 영역 끝 2012-01-20 --> <div id="noPrint1"> <? // 인쇄시 미포함 영역 1 ?>  <script languege="javascript" src="<?=$g4[path]?>/js/popupcalendar.js"></script><script  type="text/javascript" src="<?=$g4[path]?>/js/popupcalendar.js"></script> <!-- 메인화면 최신글 시작 --><table width=750 border=0 cellpadding=0 cellspacing=0 align=center><form name=flist><? /* <form name=flist method=get style="margin:0px;"> */ ?><input type=hidden name=doc     value="<?=$doc?>"><input type=hidden name=sort1   value="<?=$sort1?>"><input type=hidden name=sort2   value="<?=$sort2?>"><input type=hidden name=page    value="<?=$page?>"><input type=hidden name=bo_table value="<?=$bo_table?>"><tr><td colspan=3 height=20 ></td></tr><tr>    <td colspan=3>        &nbsp;&nbsp;<font color=#002fc6 size=3><b> | 기간별 내역 조회 |</b></font>        &nbsp;&nbsp;<!--<a href="<?=$board_skin_path?>/no_ok.php?bo_table=<?=$bo_table?>"><font color=green>|미결재검색|</font></a>-->     <input type=button value="프린트" onclick="window.print()">        <input type=button value="창닫기" onclick="javaScript:self.close()">    </td></tr><p><!--<tr>    <td colspan=3 align=right>        <input type=button value="인쇄보기" onclick="window.ieExecWB(7)">        <input type=button value="Page설정" onclick="window.ieExecWB(8)">        <input type=button value="대화상자" onclick="window.ieExecWB(6)">        <input type=button value="인쇄하기" onclick="window.ieExecWB(6, -1)">        &nbsp;        <input type=button value="프린트" onclick="window.print()">        <input type=button value="창닫기" onclick="javaScript:self.close()">    </td></tr>--><tr><td colspan=3 height=10 ></td></tr><tr>    <td width=10%>        <a href='<?=$_SERVER[PHP_SELF]?>?bo_table=<?=$bo_table?>'>처음</a> </td>    <td width=70% align=center>        검색기간 :  <input  type="text" name=fr_date id="wr_1" value="<?=$to_date?>" size="12" onclick="fnPopUpCalendar(this, fr_date ,'yyyymmdd')" class='text_box1'> ~                <input  type="text" name=to_date id="wr_3" value="<?=$to_date?>" size="12" onclick="fnPopUpCalendar(this, to_date ,'yyyymmdd')" class='text_box1'>        <? /* <form name="category2" method="get"> */ ?>        <select name=gubun>   <option value=''>전체</option>            <option value='임원'>임원</option>            <option value='관리부'>관리부</option>            <option value='생산1과'>생산1과</option>            <option value='생산2과'>생산2과</option>            <option value='생산기술부'>생산기술부</option>            <option value='제품기술부'>제품기술부</option>            <option value='구매자재부'>구매자재부</option>            <option value='사업관리부'>사업관리부</option>            <option value='품질보증부'>품질보증부</option>        </select>         <input type="text" name="gubun2" value="<?php echo $gubun2; ?>" size="15" itemname="수정내용" maxlength="20" />        <!--<script> document.flist.gubun.value = '<?=$gubun?>';</script> -->        <input type=image src="./img/search_btn.gif" border=0 align=absmiddle>    </td>  <td width=20% align=right>건수 : <? echo $total_count ?>&nbsp;</td> </tr><tr><td colspan=3 height=1 bgcolor=#CCCCCC></td></tr></table><p></div> <? // 인쇄시 미포함 영역 1 끝 ?><div id="startPrint"> <? // 인쇄영역 시작 ?><table width=750 border=0 cellpadding=0 cellspacing=0 align=center><?for ($i=0; $row=mysql_fetch_array($result); $i++) {    $num = $rank + $i + 1;    if($i % 30 == 0) {        $subpage  = $subpage + 1;        if($firstpage) {        echo "            <tr>                <td colspan=10>                    <div style='font-size: 14px; font-family: dotum; font-weight: bold; margin: 5px 0;'>                    기간별조회 : [$fr_date~$to_date] Page $subpage/$printpage                    </div>                </td>            </tr>        ";        } else {        echo"            <tr>                <td colspan=10>                <div style='font-size: 14px; font-family: dotum; font-weight: bold; margin: 5px 0;'>    기간별조회 : [$fr_date~$to_date] Page $subpage/$printpage    </div>                </td>            </tr>        ";        }    $firstpage = 1; echo " <tr><td colspan=10 height=3 bgcolor=#0E87F9></td></tr><tr height='20px' align='center'> <th rowspan='2' style='width: 40px;'>번호</th> <th width='90px' rowspan='2'>  요일 </th> <th width='170px' colspan='2' rowspan='2'>  부서/이름 </th> <th width='130px' rowspan='2' style='text-align: center; padding-right:15px;'>  잔업시간 </th> <th width='50px' rowspan='2' style='text-align: center; padding-right:15px;'>  식사 </th>  <th width='50px' rowspan='2' style='text-align: center; padding-right:15px;'>  빵/우유 </th> <tr></tr> "; }    $list = $i%2; $row[wr_1] = substr($row[wr_1],2,6);    // 00000000 날짜를 년월일만 취해서 000000으로 표시    // 00.00.00 으로 이미 입력된 데이타고려 // 검색내역총계(페이지합)            $sub_suip1 += $row[wr_3];            $sub_suip2 += $row[wr_4];            $sub_jich1 += $row[wr_content];            $sub_jich2 += $row[wr_5];            $sub_jich3 += $row[wr_2];    $sub_sum_total1 = $sub_suip1 - $sub_jich1;    $sub_sum_total2 = $sub_suip2 - $sub_jich2;    $sub_sum_total3 = $sub_suip2;      echo "    <tr class='list$list center'>        <td height=25 style='text-align:center;'>$num</td>        <td style='text-align:center;'><font color=#002fc6>$row[wr_1]</font></td>        <td style='width: 100px; text-align:center;'>$row[ca_name]</td>      <td style='width: 40px; text-align:center;'>$row[wr_9]</td>        <td style='width: 150px; text-align: center;'>$row[wr_4]</td> "; echo "          <td style='width: 60px; text-align:center;'>$row[wr_content]</td>         <td style='width: 40px; text-align:center;'>$row[wr_5]</td>  "; echo "    </tr> <tr><td colspan=10 height=1 bgcolor=#F5F5F5></td></tr>"; // 라인사이 공백} if ($i == 0) {    echo "<tr><td colspan=10 align=center height=100 bgcolor=#ffffff><span class=point>자료가 한건도 없습니다.</span></td></tr>\n";}?><tr><td colspan=10 height=1 bgcolor=CCCCCC></td></tr></table><div style='font-size: 14px; font-family: dotum; font-weight: bold; margin: 15px 0 0 0;'>    &nbsp;&nbsp;&nbsp;기간별내역 합계 : [<?=$fr_date?> ~ <?=$to_date?>]</div><table width=750 border=0 cellpadding=0 cellspacing=0 align=center><tr>    <td width=50%>&nbsp;</td>    <td width=50% align=right><?=get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?bo_table=$bo_table&$qstr1&page=");?></td></tr></table><TABLE width="750" border=1 cellspacing="0" bordercolordark="white" bordercolorlight="black" bordercolor="#cacaca" align=center>    <tr>        <td align=center><font color=#002fc6>기간별 합계</font></td>        <td align=center>식사 인원합계</td>        <td align=center>빵/우유 인원합계</td>        <td align=center>총 잔업시간</td>    </tr>    <tr>        <td align=center>단위 합계</td>        <td align=right><font color='red' size='2'>&nbsp;&nbsp;<?=number_format($sub_jich1)?>명&nbsp;</b></font></td>         <td align=right><font color='red' size='2'>&nbsp;&nbsp;<?=number_format($sub_jich2)?>명&nbsp;</b></font></td>        <td align=right><font color='red' size='2'>&nbsp;&nbsp;<?=number_format($sub_sum_total3)?>시간&nbsp;</b></font></td>    </tr></table></td></tr></table><!-- 메인화면 최신글 끝 --><? //include_once("$g4[path]/_tail.php"); include_once("$g4[path]/tail.sub.php");?>

 
|

답변 1개

채택된 답변
+20 포인트

for문 위에

 

$bbang_count = 0;

$siksa_count = 0;

 

넣고

 

for문 중간에

 

if($row[wr_content]=="식사"){

$siksa_count += $siksa_count+1;

}

 

if($row[wr_content]=="빵"){

$bbang_count += $bbang_count+1;

 

}

 

for문 바깥에서 출력하시면 되요

<?=number_format($siksa_count)?>

<?=number_format($$bbang_count)?>

 

직접한게 디버깅하면서 볼수 없으니

대략적으로

 

1. for문 위에서 변수를 설정

2. for문 안에서 식사이면 +1 , 빵이면 +1

3. for문 바깥에서 변수 출력

 

 

답변을 작성하려면 로그인이 필요합니다.