如何将链接放入数据库中的<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>

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

remove echo from query and concat with .

like

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

because you already write link between <?php echo ?> tag so you can not use echo inside echo you use . concat operator instead of echo so it will work.

You have an extra 'echo'

Replace

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

with

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

This line:

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

You could write as:

<a href="<?=$r->link?>"><?=$r->title?></a>

More info: http://php.net/manual/en/language.basic-syntax.phptags.php

You are missing a ; between your two echo calls.

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

But as Stony already suggested, it´s preferrable to use only one echo call here.