我有以下代码,但在第7行继续遇到语法错误,说"解析错误:语法错误,意外' htmlentities' (T_STRING)&#34。这不是同时回应php和html的正确方法吗?任何帮助表示赞赏!
<?php
$stmt = $pdo->query("SELECT first_name, last_name, department, website filename FROM Profile");
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
echo('<div class="col-sm-3">
<img class="img-rounded" src="'.$row['filename'].'"/>
<p class="caption">');
echo('<a href="'htmlentities($row['website'])'">'.($row['first_name']).' '.htmlentities($row['last_name']).'</a>')
echo(', '.htmlentities($row['department']));
echo('</p> </div>');
}
?>
答案 0 :(得分:0)
你的回音应该没有括号,你就错过了。在一些echo命令上。
答案 1 :(得分:0)
要连接回显字符串(连接),您需要添加带有“。”的字符串。
请使用:
<?php
$stmt = $pdo->query("SELECT first_name, last_name, department, website filename FROM Profile");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="col-sm-3">
<img class="img-rounded" src="' . $row['filename'] . '"/>
<p class="caption">';
echo '<a href="' . htmlentities($row['website']) . '">' . ($row['first_name']) . ' ' . htmlentities($row['last_name']) . '</a>';
echo ', ' . htmlentities($row['department']);
echo '</p> </div>';
}
?>
答案 2 :(得分:0)
当你打断像
这样的字符串时,你应该连接你的字符串echo('<a href="' . htmlentities($row['website']) . '">'.($row['first_name']).' '
在htmlentities部分,你缺少stringconcatenation的点
答案 3 :(得分:0)
你以错误的方式连接了字符串。试试以下
<?php
$stmt = $pdo->query("SELECT first_name, last_name, department, website, filename
FROM Profile");
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) )
{
echo '<div class="col-sm-3">
<img class="img-rounded" src="'.$row['filename'].'"/>
<p class="caption">';
echo '<a href="'.htmlentities($row['website']).'">'.$row['first_name'].' '.htmlentities($row['last_name']).'</a>';
echo ', '.htmlentities($row['department']);
echo '</p> </div>';
}
?>
或
您也可以尝试以下方式作为替代方式..
<?php
$stmt = $pdo->query("SELECT first_name, last_name, department, website, filename
FROM Profile");
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) )
{
?>
<div class="col-sm-3">
<img class="img-rounded" src="<?php echo $row['filename'] ?>"/>
<p class="caption">
<a href="<?php echo htmlentities($row['website']) ?>">
<?php echo $row['first_name'].' '.$row['last_name'] ?>
</a>
<?php echo ', '.htmlentities($row['department']); ?>
</p>
</div>
<?php
}
?>
答案 4 :(得分:0)
我编辑你尝试过的代码。你想念 。和;
echo '<div class="col-sm-3">
<img class="img-rounded" src="'.$row['filename'].'"/>
<p class="caption">';
echo '<a href="'.htmlentities($row['website']).'">'.($row['first_name']).' '.htmlentities($row['last_name']).'</a>';
echo ', '.htmlentities($row['department']);
echo '</p> </div>';
&#13;