我想在末尾添加.html或从数据库和 php 查询中获取完整的 url 回显


I want to add .html at the end or a full url fetch from Database and php query between echo

我将为我的博客编写以下代码。但是问题,我面临:

"echo 'a href=".$query2['url']."</a>'; " 我想在 echo 中添加.$query2['url'].,也想在 url 末尾添加.html,例如"a href=".$query2['url'].html."。

如果您有任何想法,请尽快告诉我,谢谢。基本上我正在从数据库中获取这些数据。

<?php
$start=0;
$limit=5;
if(isset($_GET['id']))
{
    $id=$_GET['id'];
    $start=($id-1)*$limit;
}
$query=mysql_query("select * from tbl_services LIMIT $start, $limit");
echo "<div class='entry'>";
while($query2=mysql_fetch_array($query))
{
       echo '<a href=".$query2['url']."><h2>' .$query2['name'].'</h2></a>';
    echo "<p>".$query2['Contents']."</p>";
    echo "<div class='meta'><i class='fa fa-clock-o'></i>".$query2['date'].  "<b><i class='fa fa-user'></i></b>  Written by <strong>Arslan Ali</strong>   <b><i class='fa fa-comment-o'></i></b>"  ;
echo "</div>";
}
echo "</div>";
$rows=mysql_num_rows(mysql_query("select * from tbl_services"));
$total=ceil($rows/$limit);
echo "<ul class='pagination'>";
if($id>1)
{
    echo "<li><a href='?id=".($id-1)."' class='disabled'><<</a></li>";
}
        for($i=1;$i<=$total;$i++)
        {
            if($i==$id) { echo "<li class='current'>".$i."</li>"; }
            else { echo "<li><a href='?id=".$i."'>".$i."</a></li>"; }
        }
if($id!=$total)
{
        echo "<li><a href='?id=".($id+1)."' class='disabled'>>></a></li>";
}
echo "</ul>";
?>

(更新)替换此行

echo '<a href=".$query2['url']."><h2>' .$query2['name'].'</h2></a>';

echo "<a href='".$query2['url'].".html'>".$query2['name']."</a>";

语法错误的解决方案仍然存在一个问题。 href 用单引号引起来。 这不是正确的语法。通过反转单引号和双引号的使用很容易补救,如我在这里所示。

echo '<a href="' . $query2['url'] . '.html">' . $query2['name']. '</a>';