gpt4 book ai didi

php - 如何在ZF2中对MySQL数据库表的特定属性设置条件?

转载 作者:行者123 更新时间:2023-11-29 11:03:24 24 4
gpt4 key购买 nike

This is the code, and i want to set condition on obtainedMarks. The condition will check if the obtainedMarks have a value assigned or not.

 $qb->select(array(
"academic.studentAcademicId as studentAcademicId",
"academic.descriptions as descriptions",
"student.name as studentName",
"student.studentId as studentId",
"class.name as className",
"session.name as sessionName",
***"SUM(marks.marksObtained) as marksObtained",***
))
->from('Application\Entity\StudentAcademics','academic')
->leftJoin('academic.class','class')
->leftJoin('academic.marks','marks')
->leftJoin('academic.student','student')
->leftJoin('academic.session','session')
->where('academic.student = :student')
->setParameter('student',$studentId)->groupBy('studentAcademicId');

那么如何设置这样一个条件来检查 obtainedMarks 是否带有值......!

最佳答案

In Zendframework2, all query data is assigned to an array variable e.g $data

 $data = $qb->getQuery()->getScalarResult();

and is returned to whoever call this controller i.e,

return new ViewModel(array(
'data' => $data,
)

To check if a specific attribute in a query bears a value or not is to check it through foreach loop in the view that called this controller e.g

<?php foreach ($this->data as $item): ?>
<tr>
<td>
<?php if(isset( $item['marksObtained']) && $item['marksObtained'] > 0){?>
<a href="<?=$this->url( 'marks/details', array('action'=>'index', 'id'=>$item['studentAcademicId']))?>">
<?php echo $item['marksObtained']; ?></a>
<?php }else{ ?>
<a href="<?=$this->url( 'marks/details', array('action'=>'add', 'id'=>$item['studentAcademicId']))?>">
Add Marks</a>
<?php }?>
</td>
</tr>

As seen, the if condition is checking out the obtainedMarks value from the data array variable.

关于php - 如何在ZF2中对MySQL数据库表的特定属性设置条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41826188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com