这个问题在这里已经有答案了:
引用-这个错误在php中是什么意思(36个答案)
两年前关门了。
我的控制器:
function generateallmonthreport()
{
$month = $this->input->post('month');
$year = $this->input->post('year');
$familyid = $this->session->userdata('family_id');
$fulldata['dates'] = $this->Itemreport_model->getreportallmonth($month,$year);
$fulldata['members1'] = $this->Itemreport_model->getindependentmembers($familyid);
$fulldata['members2'] = $this->Itemreport_model->getindependentmembers($familyid);
$fulldata['members3'] = $this->Itemreport_model->getindependentmembers($familyid);
$fulldata['members4'] = $this->Itemreport_model->getindependentmembers($familyid);
$fulldata['members5'] = $this->Itemreport_model->getindependentmembers($familyid);
$fulldata['year'] = $year;
$fulldata['month'] = $month;
$this->load->view('header');
$this->load->view('itemreports/allmonthreportpage', $fulldata);
$this->load->view('footer');
}
我的型号:
function getreportallmonth($month,$year)
{
$sql = "SELECT DISTINCT `item_date` FROM `items` WHERE MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year'";
$query = $this->db->query($sql);
return $query->result();
}
function getindependentmembers($familyid)
{
$sql = "SELECT * FROM `familymember` WHERE `family_id`='$familyid' AND `dependency`='1'";
$query = $this->db->query($sql);
return $query->result();
}
function getcountofexpensetype($memberid,$year,$month)
{
$sql = "SELECT COUNT(DISTINCT `item_expensetype`) AS spancount FROM `items` WHERE `item_purchaseby`='$memberid' AND MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year' AND `item_expensetype` IS NOT NULL";
$query = $this->db->query($sql);
return $query->result();
}
function getexpensetype($memberidforexpensetype,$year,$month)
{
$sql = "SELECT DISTINCT `item_expensetype` as expensetype FROM `items` WHERE `item_purchaseby`='$memberidforexpensetype' AND MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year' AND `item_expensetype` IS NOT NULL";
$query = $this->db->query($sql);
return $query->result();
}
function getallitems($thisdate)
{
$sql = "SELECT `item_name`,`item_price`,`item_purchasetype` FROM `items` WHERE `item_date`='$thisdate'";
$query = $this->db->query($sql);
return $query->result();
}
function getexpensetypefinal($memberidforexpensetypeprice,$year,$month)
{
$sql = "SELECT DISTINCT `item_expensetype` as expensetype FROM `items` WHERE `item_purchaseby`='$memberidforexpensetypeprice' AND MONTH(`item_date`)='$month' AND YEAR(`item_date`)='$year' AND `item_expensetype` IS NOT NULL";
$query = $this->db->query($sql);
return $query->result();
}
我的观点:
<table border="2" id="tab" style="width:100%" class="text-center m-auto table table-bordered table-hover">
<tr>
<td rowspan="2">Date</td>
<td rowspan="2">Items</td>
<!-- php code for getting all individual member header for individual expense types -->
<?php foreach ($members1 as $members1) { ?>
<?php
$this->load->model('Itemreport_model');
$memberid = $members1->member_id;
$countforcolspan = $this->Itemreport_model->getcountofexpensetype($memberid,$year,$month);
?>
<td colspan="<?php foreach ($countforcolspan as $countforcolspan) { echo $countforcolspan->spancount+1; } ?>">
<?php echo $members1->membername."'s Individual Expenses"; ?>
</td>
<?php } ?>
<td rowspan="2">Total Expense On Common</td>
<!-- php code for getting all individual member header -->
<?php foreach ($members2 as $members2) { ?>
<td rowspan="2"><?php echo $members2->membername."'s Total Expense (Individual + Common)"; ?></td>
<?php } ?>
<td rowspan="2">Total Expense Of Family</td>
</tr>
<tr>
<?php
foreach ($members3 as $members3) {
$memberidforexpensetype = $members3->member_id;
$expensetype = $this->Itemreport_model->getexpensetype($memberidforexpensetype,$year,$month);
foreach ($expensetype as $expensetype) { ?>
<td><?php echo $expensetype->expensetype; ?></td>
<?php } ?>
<td>Total</td>
<?php }
?>
</tr>
<tbody id="tbodydata">
<?php foreach ($dates as $dates) { ?>
<tr>
<td><?php $thisdate = $dates->item_date; echo $thisdate; ?></td>
<td><?php
$allitems = $this->Itemreport_model->getallitems($thisdate);
foreach ($allitems as $allitems) {
echo $allitems->item_name; ?> (<?php echo $allitems->item_price; ?>)
<?php }
?></td>
<?php foreach ($members4 as $members4) {
$memberidforexpensetypeprice = $members4->member_id;
$countforcolspan = $this->Itemreport_model->getexpensetypefinal($memberidforexpensetypeprice,$year,$month);
} ?>
</tr>
<?php } ?>
</tbody>
代码似乎工作得很好,但给我的通知,试图获得非对象的属性
错误:
遇到php错误严重性:注意消息:尝试获取非对象的属性文件名:itemreports/allmonthreportpage.php行号:68
回溯:文件:d:\wampserver\www\home\application\views\itemreports\allmonthreportpage.php行:68函数:\u error\u handler
文件:d:\wampserver\www\home\application\controllers\itemreport.php行:91函数:view
文件:d:\wampserver\www\home\index.php行:315函数:require\u once
我看不出代码中的impropper部分。。请帮忙。。!!
1条答案
按热度按时间aij0ehis1#
如注解所示,不能使用保存数组的变量来同时保存值,如中所示
foreach ($members4 as $members4)
. 它将覆盖保存在中的值$members4
,这使得循环做了一些你意想不到的事情。要解决这个问题,只需使用不同的变量,例如
$member
比如这里: