背景
a_aif表中选择四个字段a_aif.aif_id等于remaining_if.aif_id的行背景)。remaining_aifs。problem -请查看红色箭头/高亮显示的语法,我认为问题在哪里.

PHP脚本
<?php
require_once 'config.php';
$dbh = new PDO($dsn, $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$result = $dbh->query("
SELECT a_aif.aif_id,
a_aif.fee_source_id,
a_aif.company_name_per_sedar,
a_aif.document_filing_date,
IF (a_aif_remaining.aif_id IS NULL, 0, 1) remaining_aifs
FROM a_aif
LEFT JOIN a_aif_remaining
ON a_aif_remaining.aif_id = a_aif.aif_id
ORDER BY aif_id DESC");
$result->setFetchMode(PDO::FETCH_ASSOC);
if ( !empty($result) ) : endif;
?>
<table>
<tr>
<th><b>Document ID</b></th>
<th><b>Pubco Name</b></th>
<th><b>Filing Date</b></th>
<th><b>PDF</b></th>
</tr>
<?php foreach($result as $index => $row) : ?>
<tr
<?php
if('a_aif.aif_id' === 'remaining_aifs'
echo "<tr class='highlighted'>";
else echo "<tr>";
?>
>
<td><?php echo $row[fee_source_id]; ?></td>
<td><?php echo $row[company_name_per_sedar]; ?></td>
<td><?php echo $row[document_filing_date]; ?></td>
<td></td>
</tr>
<?php endforeach;
$dbh = NULL;
?>
</table>发布于 2013-01-03 07:18:46
1) empty()是一个结构,如果您传递的值为以下任一值,则返回true:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)2) $result是传递给empty()的一些值。不知道它被设置为什么,因为您没有发布任何其他代码。
3) :是为if语句定义块的另一种语法。您需要在块的末尾使用endif;结束它。
当使用PHP与HTML混合(通常是在模板中)时,这种替代语法非常流行。您的代码可能如下所示:
<?php if ( !empty($result) ) : ?>
<span class="result"><?php echo $result; ?></span>
<?php endif; ?>请注意,您在<?php if...和<?php endif; ?>行之间放置的内容可以是任何内容,包括更多的php代码或html/text。
更多信息:
http://www.php.net/empty
http://www.php.net/manual/en/control-structures.alternative-syntax.php
发布于 2013-01-03 07:16:11
这是"if语句“的交替语法。
您可以使用
<?php
if ($condition):
//some code
else:
// some code
endif;
?>因此,在示例1和2中是条件,如果结果不是空的,则传递条件。
发布于 2013-01-03 07:35:38
数组如下所示:
$result= array(); // array defined
$result= ["name","last name"]; // array elements
$result= []; // empty arrayIf语法:
<?php if ( !empty($result) ) : ?>
hello control in if
<?php else: ?>
in else condition
<?php endif; ?>其中,empty();是一个用于检查$result的php函数,它没有任何元素,也没有元素。
:是一个语法元素。
https://stackoverflow.com/questions/14134545
复制相似问题