Q:

Problem with PHP Syntax

I am trying to get a link together using 2 variables but the output is the link and title but no html / clickable link appearing.
I'm getting something link this:
http://www.mydomain.com/post1/post_title_here
Here is the code:
echo '<a href="'.the_permalink().'">'.the_title().'</a>';

Can anyone help please?
Thanks
UPDATE:
Here's the whole block of code:
<div id="MyBlock1">
        <?php
            $query = new WP_Query('posts_per_page=5');

             while( $query ->have_posts() ) : $query ->the_post();
                 echo '<li>';
                 echo '<a href="'.the_permalink().'">'.the_title().'</a>';
                 echo '</li>';
             endwhile;

            wp_reset_postdata();

        ?>
    </div>

A:

That's because the wordpress functions the_permalink() and the_title() display the respective outcomes already they need not be echoed. If you want functions that return the values, you have to use get_permalink() and get_the_title() instead.
So either do:
<div id="MyBlock1">
    <?php
        $query = new WP_Query('posts_per_page=5');
        while( $query ->have_posts() ) : $query ->the_post();
            echo '<li>';
            echo '<a href="'.get_permalink().'">'.get_the_title().'</a>';
            echo '</li>';
        endwhile;
        wp_reset_postdata();
   ?>
</div>

or
<div id="MyBlock1">
    <?php
        $query = new WP_Query('posts_per_page=5');
        while( $query ->have_posts() ) : $query ->the_post();
            echo '<li><a href="';
            the_permalink();
            echo '">';
            the_title();
            echo '</a></li>';
        endwhile;
        wp_reset_postdata();
   ?>
</div>

Both will work.

