dsz1966 2017-11-07 13:29
浏览 165

如何将链接放入数据库中的<a href>标签[重复]

This question already has an answer here:

So i am building this search engine, and i have some websites inside my database. But i want to do like so i can "href" to the link i have placed inside the database. This is my code i was trying to use but didn't work:

if($query->num_rows) {
        while($r = $query->fetch_object()) {
            $rlink = $r->link;
            ?>

                <div class="result">
                    <?php echo '<a href="' .$r->link. '">' echo $r->title . "</a>"?>
                </div>
            <?php
        }
    }

And this is the error:

Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in X:\xamppUSE\htdocs\search\search.php on line 33

</div>
  • 写回答

5条回答 默认 最新

  • duansha6410 2017-11-07 13:31
    关注

    You syntax is not correct.

    <?php echo '<a href="' .$r->link. '">' . $r->title . '</a>' ?>
                                          ^^^   
    

    you can't use echo in an echo so you have to concat the variable

    评论

报告相同问题?