저는 PHP로 데이터 분석 도구를 구축하고 있습니다. Postgres와 데이터를 표시하는 프로덕션 서버를 쿼리하고 있습니다.PostgreSQL이 쿼리에서 가져온 데이터를 표시합니다.
1 반복 :
Country sum(yesterday)
India 4500
Southafrica 5000
2 반복 :
country sum(day before)
India 5000
Southafrica 7000
Japan 4000
나는 다음과 같은 출력을 표시 루프에서 내 선택 쿼리를 (날짜 변수로 전달됩니다) 실행 해요
이렇게 테이블에 표시하고 싶습니다.
Country yesterday daybefore
India 4500 5000
Southafrica 5000 7000
Japan empty 4000
나는 어떤 도움이 좋을 것
http://net.tutsplus.com/tutorials/php/simple-php-class-based-querying/
이 튜토리얼에 따라 DAL를 작성했습니다.
Query sample : this is run twice in a loop where $date = array('1','2')
query : select c.country_name, sum(tf.tx_amount_usd)
from
table1 tf,
table2 tp,
table3 d,
table4 c
where
tf.condition = tp.condition
and d.day = current_date-$date
group by 1,2 order by 2
가져 오기 데이터 :
$results = array();
while ($row = pg_fetch_array($res)){
$result = new DALQueryResult();
foreach ($row as $k=>$v){
$result->$k = $v;
}
$results[] = $result;
}
return $results;
표시 데이터 :
$dal = new DAL();
$dates = array('1','2');
foreach ($dates as $date) {
$results = $dal->get_trans_by_date($date);
echo "<h1>Data</h1>";
// check if there were any results
if ($results) {
// cycle through results
foreach ($results as $model) {
/* echo "<pre>";print_r($results);echo "</pre>"; */
echo "<li>$model->country_name ".number_format($model->sum,2)."</li>";
}
}
else {
// Display a message concerning lack of data
echo "<p>No Query Output.</p>";
}
}
데이터를 검색하고 출력하는 데 사용하는 코드를 제공하면 대답하기가 더 쉬울 것입니다. –