Html链接<a> not wrapping </a> <div> <a> element properly

时间:2015-07-23 17:48:20

标签: php html

I am currently writing a php website where I encountered a problem where the html link will not wrap div element properly. I have not found an answer to my problem yet, so I appreciate if someone can help me.

This is the php code I had written:

 ECHO '<a target="_blank"  href="' . $row["link"] . '">';
 ECHO '<div class="header-box">';
 ECHO '<div class="detail">';
 ECHO '<p class="title">' . $row["title"] . '</p>';
 $user_data = get_user_data($row["owner_id"]);
 ECHO '<p class="author">This article is shared by <a class="user" href="./member.php?action=profile&id='.$user_data["id"].'">' . $user_data["firstname"] . " " . $user_data["lastname"] . '</a> on '.date("d F Y", strtotime($row["posted"])).'.</p>';
 ECHO '</div>';
 ECHO '<div class="good">';
 ECHO '<p id="number">'.$row["good"].'</p>';
 ECHO '<p id="icon"><i class="fa fa-thumbs-o-up"></i>Useful</p>';
 ECHO '</div>';
 ECHO '<div class="bad">';
 ECHO '<p id="number">'.$row["bad"].'</p>';
 ECHO '<p id="icon"><i class="fa fa-thumbs-o-down"></i>Not Useful</p>';
 ECHO '</div>';
 ECHO '</div>';
 ECHO '</a>';

However, the outcome of the php code in browser are as followed:

<div class="header-box">
<a target="_blank" href="http://designinstruct.com/tools-basics/5-easy-steps-optimize-your-images-photoshop/"></a>
<div class="detail">
<a target="_blank" href="http://designinstruct.com/tools-basics/5-easy-steps-optimize-your-images-photoshop/">
<p class="title">5 Easy Steps to Optimize Your Images in Photoshop</p>
</a>
<p class="author"><a target="_blank" href="http://designinstruct.com/tools-basics/5-easy-steps-optimize-your-images-photoshop/">This article is shared by </a><a class="user" href="./member.php?action=profile&amp;id=2">demoname demo</a> on 01 January 1970.</p>
</div>
<div class="good"><p id="number">1</p><p id="icon"><i class="fa fa-thumbs-o-up"></i>Useful</p></div>
<div class="bad"><p id="number">2333</p><p id="icon"><i class="fa fa-thumbs-o-down"></i>Not Useful</p>
</div></div>

I am getting a little bit frustrated trying to fix the problem because I can't figure out what is going wrong? The other part of code written with html link wrapping the div are working fine. Can anyone help me out? Thanks.

3 个答案:

答案 0 :(得分:1)

所以Rick Hitchcock解决了我的嵌套问题。

所以答案不是在另一个标签中嵌套标签。

答案 1 :(得分:0)

为什么要使用纯PHP?这不是必需的?

答案 2 :(得分:0)

看到重构的代码后,我意识到你在另一个链接中有一个链接。浏览器不知道该怎么做,因此它会尽可能小地关闭它们。

尝试在.php文件中使用html,只使用必须使用php的标签。例如:

使用?&gt;关闭php,然后在每次需要时打开它,将代码包装在

<?php //php code goes here ?>

您的代码已重构:

<a target="_blank"  href="<?php echo $row["link"] ?>">
<div class="header-box">
    <div class="detail">
        <p class="title"><?php echo $row["title"] ?></p>
        <?php $user_data = get_user_data($row["owner_id"]); ?>
         <p class="author">This article is shared by <a class="user" href="./member.php?action=profile&id=<?php echo $user_data["id"] ?>"><?php echo $user_data["firstname"] ?> <?php echo $user_data["lastname"] ?></a> on <?php echo date("d F Y", strtotime($row["posted"])) ?></p>
    </div>
    <div class="good">
        <p id="number"><?php echo $row["good"] ?></p>
        <p id="icon"><i class="fa fa-thumbs-o-up"></i>Useful</p>
    </div>
    <div class="bad">
        <p id="number"><?php echo $row["bad"] ?></p>
        <p id="icon"><i class="fa fa-thumbs-o-down"></i>Not Useful</p>
    </div>
</div>
</a>