「dp」というテーブルがあると仮定します
Year | Month | Payment| Payer_ID | Payment_Recipient |
2008/2009 | July | 100000 | 1 | John |
2008/2009 | August | 200000 | 1 | Jane |
2009/2010 | August | 150000 | 1 | Jane |
2009/2010 | September | 175000 | 1 | John |
mysqlビューで:
Year | July | August | September |
2008/2009 | 100000 | 200000 | 0 |
2009/2010 | 0 | 150000 | 175000 |
私のphpページに次のような出力が必要です:
Year | July | August | September |
2008/2009 | 100000 | John | 200000 | Jane | 0 | - |
2009/2010 | 0 | - | 150000 | Jane | 175000 | John |
私はこのコードのいくつかを使用します:
$query_Recordset1 = "SELECT
year
, SUM(IF(Month='July', Payment, 0)) As 'July'
, SUM(IF(Month='August', Payment, 0)) As 'August'
, SUM(IF(Month='September', Payment, 0)) As 'September'
FROM
dp
WHERE
Payer_ID = 1
GROUP BY
Year";
<?php do { ?>
<tr>
<td><?php echo $row_Recordset1['year']; ?></td>
<td><?php
$monthfilter=$row_Recordset1['month'];
$valuefromfilter=$row_Recordset1['payment'];
if ($monthfilter == 'July')
{
echo $valuefromfilter;
}
else
{
echo "<center>";
echo "<font color=red><b>0</b></font>";
echo "</center><br>";
}
?></td>
<td>script for august</td>
<td>script for september</td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
そして、それは次のようになりました:
Year | July | August | September |
2008/2009 | * | * | * |
2009/2010 | * | * | * |
- = 未定義インデックス ....
PHPページでの出力の解決策はありますか?