Extra Form
PHP PHP 7.2
CMS Rhymix

디버그 하기 좀 편하게 코드를 고쳤는데요.

 

 

            $args = new stdClass();
            $args->document_srl = $obj->document_srl;
            $doc_read_history = executeQuery('sitemanagement.docRead_get',$args)->data['1'];
            
            //회원정보 구함
            $logged_info = Context::Get('logged_info');
            if($logged_info) $args->member_srl = $logged_info->member_srl;
            
            //db처리
            if($doc_read_history){
                //추가 변수정리
                $readed_count = executeQuery('sitemanagement.docRead_get',$args)->data->readed_count;
                $plus = 1;
                $args->readed_count = $readed_count + $plus;
                $args->module_srl = $obj->variables['module_srl'];
                $args->title = $obj->variables['title'];
                $args->referrer = $referer['host'];                
                executeQuery('sitemanagement.docRead_update',$args);    //문서 조회기록 있으면 업데이트
            }else{
                //추가 변수정리
                $args->readed_count = 1;
                $args->module_srl = $obj->variables['module_srl'];
                $args->title = $obj->variables['title'];
                $args->referrer = $referer['host'];
                executeQuery('sitemanagement.docRead_insert',$args);    //문서 조회기록 없으면 db입력
            }

 

 

업데이트 시는 저 readed_count 가 1씩 증가되도록 했는데  $readed_count이 빈 값으로 가져오는지  $plus 값으로 들어갑니다.

 

$plus 값 을 2로 바꾸면 2로 업데이트가 되니 $readed_count 에 담은 $doc_read_history->data->readed_count 부분에 제가 오류를 범하고 있는 것 같은데 어떻게 바꿔야 하는지 잘 모르겠네요.

 

 

잘 안되서 코드를 조금 바꿔봤는데 여전히 동일한 문제가 해결이 안되네요.

  • profile

    ->data['1'] 이 부분이 좀 수상한데요. $doc_read_history 값이 제대로 안 들어가 있을 확률이 높습니다.

  • profile profile

    일단 해당부분은 원래 있던 코드인데 해당부분으로는 $doc_read_history 값이 잘 구분되서 저 조건문이 잘 동작합니다.
    신규,업데이트 구분되서 잘 동작되는것은 확인했습니다.

    그런데 readed_count 값을 db에서 뽑아 오는게 잘 안되네요.

     

     

    $logged_info = Context::get('logged_info');
    if($logged_info->is_admin == 'Y') {
    $args = new stdClass();
    $args->document_srl = Context::get('document_srl');
    $readed_count = executeQuery('sitemanagement.docRead_get',$args)->data->readed_count;
    echo $readed_count;
    }    

     

    임의의 애드온에 위와 같이 넣고 찍어봤는데 암것도 안나오네요 ㅡㅜ

  • profile profile
    그러면 ->data->readed_count 부분에 문제가 있는 것이겠지요.
    아니면 해당 쿼리가 readed_count라는 컬럼을 아예 반환하지 않고 있거나...
    (똑같은 쿼리 결과에 ['1']이라고도 쓰고 ->readed_count라고도 쓰는 것은 이상합니다.)

    sitemanagement.docRead_get 쿼리가 어떻게 짜여져 있는지 자세히 봐야 알 수 있겠습니다.
  • profile profile

    <query id="docRead_get" action="select">
    <tables>
    <table name="sitemanagement_doc_read" />
    </tables>
    <columns>
    <column name="*" />
    </columns>
    <conditions>
    <condition operation="equal" column="document_srl" var="document_srl" />
    <condition operation="more" column="regdate" var="regdate_more" pipe="and" />
    <condition operation="notin" column="module_srl" var="exclude_module_srls" pipe="and" />
    </conditions>
    <navigation>
    <index var="sort_index" default="regdate" order="desc" />
    <list_count var="list_count" default="8" />
    <page_count var="page_count" default="1" />
    <page var="page" default="1" />
    </navigation>
    </query>


    이거는 그냥 원래 있던 쿼리라서 특별한 것은 없습니다.

     

    readed_count 는 제가 추가한 컬럼이라서요... 

  • profile profile
    쿼리는 모든 컬럼을 다 불러오도록 되어 있으니 임의로 추가하신 컬럼도 포함되어야 맞습니다.

    단, 위에서 ['1']이라고 쓰신 것이 정상 작동하였다면 아래에서 ->readed_count 문법은 맞지 않을 수도 있습니다. 전자는 배열 문법이고 후자는 객체 문법인데, 쿼리 결과가 배열이거나 객체이거나 둘 중 하나이지 둘 다는 아닐 테니까요.

    만약 배열 안에 객체가 들었다면 ->data[1]->readed_count 라고 쓰셔야 합니다. 그런데 이건 레코드가 2개 이상인 경우이고, 만약 1개만 있다면 배열 없이 그냥 객체 하나만 돌아올 테니 ->data->readed_count가 맞을 겁니다. 반면, 이런 경우에는 위쪽의 ['1']이 틀리겠지요. 레코드가 몇 개씩 돌아오는지에 따라 다르게 응용하셔야겠네요.
  • profile profile
    레코드가 뭔지는 잘 모르겠는데요.
    그냥 컬럼 몇개 있는게 전부입니다.

    <table name="sitemanagement_doc_read">
    <column name="document_srl" type="number" size="11" notnull="notnull" index="idx_document_srl" />
    <column name="title" type="varchar" size="250" />
    <column name="module_srl" type="number" size="11" notnull="notnull" />
    <column name="member_srl" type="number" size="11" notnull="notnull" />
    <column name="ipaddress" type="varchar" size="128" notnull="notnull" />
    <column name="referrer" type="varchar" size="250" />
    <column name="readed_count" type="number" size="11" />
    <column name="regdate" type="date" index="idx_regdate"/>
    </table>
  • profile profile

    컬럼=열
    레코드=행

    RXE 특성상 조건에 맞는 행이 몇 개 돌아오는지에 따라 결과가 배열로 나올 때가 있고 객체로 나올 때가 있습니다. 지금 상황은 배열로 나오는 것 같고요.

    이제 보니 쿼리에 page 정보가 있어서, 갯수와 무관하게 항상 배열로 나올지도 모르겠네요. 만약 그렇다면 ->data[1]->readed_count가 항상 맞을 겁니다.

  • profile profile
    ->data[1]->readed_count;
    이렇게 하니 값이 나옵니다!!!!!!!!
  • profile profile

    감사합니다. 이제 읽혀질때 마다 카운트가 증가하네요.

    $args = new stdClass();
    $args->document_srl = $obj->document_srl;
    $doc_read_history = executeQuery('sitemanagement.docRead_get',$args)->data['1'];

    //회원정보 구함
    $logged_info = Context::Get('logged_info');
    if($logged_info) $args->member_srl = $logged_info->member_srl;

    //db처리
    if($doc_read_history){
    //추가 변수정리
    $readed_count = $doc_read_history->readed_count;
    $plus = 1;
    $args->readed_count = $readed_count + $plus;
    $args->module_srl = $obj->variables['module_srl'];
    $args->title = $obj->variables['title'];
    $args->referrer = $referer['host'];
    executeQuery('sitemanagement.docRead_update',$args); //문서 조회기록 있으면 업데이트
    }else{
    //추가 변수정리
    $args->readed_count = 1;
    $args->module_srl = $obj->variables['module_srl'];
    $args->title = $obj->variables['title'];
    $args->referrer = $referer['host'];
    executeQuery('sitemanagement.docRead_insert',$args); //문서 조회기록 없으면 db입력
    }
    }


    이제 알려주신 코드에 맞게 이렇게 고쳤습니다.


    앞으로 새로 추가한 컬럼의 카운트 숫자로 자료를 뽑아서 검색유입에 효자가 되는 글들을 출력해서 모니터링 해 볼 수 있는 기초를 만들었네요.

    큰 도움 감사합니다.

     

    아.. 레코드가 그런 뜻이군요. 전 로우,컬럼 이렇게 부르는 줄 알았네요.

  • profile profile
    로우나 레코드나 같은 말입니다.

    이제 똑같은 쿼리를 2번 실행하고 있는 비효율성을 좀 개선해 보시지요. ㅎㅎ
  • profile profile
    쿼리는 한번으로 바뀐게 아닌가요??? 코드 다시 수정했는데 어디 한번 더 쿼리하는지 눈 크게 떠 봐야겠네요..
  • profile profile
    아, 밑에 update가 있는 것을 잘못 보고 아직도 get이 2개 있는 줄 알았네요.
    정리 잘 하신 것 같습니다.^^
  • profile profile
    ^_______^
  • ?
    와웅.. 이복잡한걸 수정하시다니 대단하세요
  • ? profile
    기존에 많이 고치긴 했는데 이렇게 꾸역꾸역 고쳐서 쓰고 있습니다. ㅋ 좋은 자료 만들어 주셔서 감사합니다.