You cannot see this page without javascript.

test/test.php

<?php
 define('__ZBXE__', true);
 define('__XE__', true);
 require_once $_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php';
 $oContext = &Context::getInstance();
 $oContext->init();
      $args->document_srl = 1608;
      $args->rateval = 1; //1점이상인 사람만 가져옴
      $output = executeQueryArray('widgets.star_rating.getStarRatedList', $args);

 echo print_r($output,true);

$oContext->close();

?>

 


widgets/star_rating/query/getStarList.xml

 

<query id="getDocumentStarRatedList" action="select">
    <tables>
        <table name="document_voted_log" />
    </tables>
    <columns>
        <column name="member_srl" />
        <column name="rateval" />
    </columns>
    <conditions>
        <condition operation="equal" column="document_srl" var="document_srl" filter="number" notnull="notnull" pipe="and" />
        <condition operation="more" column="rateval" var="rateval" filter="number" pipe="and" />
    </conditions>
</query>


 

위와 같이 test.php 파일과 getStarList.xml 이라는 파일을 생성하고 test.php를 실행하면 제대로 배열값이 표시됩니다.

 

 

*풀이하기

 

1. test.php파일에 config.inc.php 를 읽어 들이면

'config/func.inc.php' 파일을 함께 포함하게 되면 아래와 같이 func.in.php에 정의된 다양한 xe의 기본 함수를 사용할 수 있습니다.

 

    function executeQuery($query_id, $args = null) {
        $oDB = &DB::getInstance();
        return $oDB->executeQuery($query_id, $args);
    }


 

2. 단,  $oContext = &Context::getInstance(); 를 선언해 주어야 제대로 작동합니다.

 

*고민

  

xe의 모듈과 위젯의 query를 이용할 수 있다는 점은 좋지만

새로운 db query 문을 실행하기 위해서는 선택을 해야합니다.

특정 모듈의 query 폴더에 쿼리 내용의 xml 파일을 만들어 저장하여 executeQuery() 함수를 사용할 것인지

아니면  $oDB=&DB::getInstance(); 를 선언하 사용할 것인지를.

 

아래의 코드는 위와 비슷한 db값을 출력하는 내용입니다. 다른 점을 찾아보세요.

 

test/test2.php

 

<?php
 define('__ZBXE__', true);
 define('__XE__', true);
 require_once $_SERVER['DOCUMENT_ROOT'].'/config/config.inc.php';
 $oContext = &Context::getInstance();
 $oContext->init();

 $oDB = &DB::getInstance();

 

 //$args->document_srl = 1608;
 //$args->rateval = 1; //1점이상인 사람만 가져옴

$member_srl = 4;

$document_srl = 1608;
$tablename = 'db_document_voted_log';

 // 사용자가 투표한 적이 있는지 검사
 $result = $oDB->_query("select rateval from $tablename where member_srl='$member_srl' && document_srl='$document_srl'");
 $output = $oDB->_fetch($result); //배열 재구성


echo print_r($output,true);

$oContext->close();

?>

엮인글 :
List of Articles
번호 제목 글쓴이 날짜sort 조회 수
169 Linux PlayOnLinux [3] LynX 2014-11-28 418
168 Linux 커널 컴파일 [10] LynX 2014-12-08 743
167 Linux Codec [12] LynX 2014-12-08 355
166 Linux cinnamon [10] LynX 2014-12-11 287
165 Linux EPEL repository [10] LynX 2014-12-11 945
164 LinuxMint linuxmint LynX 2014-12-11 953
163 Linux lazarus 설치 [10] LynX 2014-12-17 340
162 LinuxMint LinuxMint MariaDB source 설치 [12] LynX 2014-12-19 1135
161 LinuxMint mint linux 한영키 [10] LynX 2014-12-19 385
160 Linux ibus 한영키 전환 문제 nabi [12] LynX 2014-12-19 483
159 Linux lol 설치 [9] LynX 2014-12-22 958
158 Linux ISO 마운트 [10] LynX 2014-12-22 516
157 Linux opensuse yum repository 추가 [13] LynX 2014-12-23 636
156 Linux 리눅스 게이밍 가이드 1부 : 게임을 위한 환경 설정 [10] LynX 2014-12-24 1027
155 Linux 리눅스 게이밍 가이드 2부 : 실전 게임 플레이와 문제 해결 [13] LynX 2014-12-24 714
154 Server Open Solaris 패키지 설치 및 삭제 LynX 2014-12-29 511
153 LinuxMint LinuxMint Apache source 설치 file [8] LynX 2014-12-29 571
152 LinuxMint LinuxMint PHP source 설치 [1] LynX 2014-12-30 297
151 CentOS CentOS 에 설치된 커널과 오랜된 커널 삭제하기 LynX 2014-12-30 970
150 OpenSolaris Open Solaris 설치 file [12] LynX 2014-12-30 417

XE Login