如果值qtd
大于5
则显示确定,否则为OPS。
和
如果值qtd
大于5,则显示图像1,否则显示图像2.
if ($aluno->qtd > 5) {
$numeral = "OK";
$image = "<imgsrc="link_da_image111" />";
} else {
$numeral = "OPS";
$image = "<img src="link_da_image222" />";
}
$table = new html_table();
$table->attributes = array("class" => "table table-hover table-condensed table-striped table-users slide_7");
foreach($alunos as $aluno) {
$row = new html_table_row();
$row->cells = array( $aluno->firstname . ' ' . $aluno->lastname, $aluno->user_picture, $aluno->qtd, $aluno->firstname . ' ' . $aluno->lastname, $numeral, $image, );
$table->data[] = $row;
}
echo html_writer::table($table);
我希望结果是这样的
Joan --- 34 ---- OK
Marr --- 2 ---- OPS
Richar --- 34 ---- OK
Otvr --- 1 ---- OPS
答案 0 :(得分:1)
if
语句必须位于foreach
循环内,以便它可以引用为$aluno
的每个元素设置的$alunos
变量。
$table = new html_table();
$table->attributes = array("class" => "table table-hover table-condensed table-striped table-users slide_7");
foreach($alunos as $aluno) {
if ($aluno->qtd > 5) {
$numeral = "OK";
$image = "<imgsrc="link_da_image111" />";
} else {
$numeral = "OPS";
$image = "<img src="link_da_image222" />";
}
$row = new html_table_row();
$row->cells = array( $aluno->firstname . ' ' . $aluno->lastname, $aluno->user_picture, $aluno->qtd, $aluno->firstname . ' ' . $aluno->lastname, $numeral, $image, );
$table->data[] = $row;
}
echo html_writer::table($table);