Get attachment if matches a variable

$attachments holds array of posts, you are missing something like:

$attachment = $attachments[0];

or

foreach( $attachments as $attachment )

Update

Nope, like this:

foreach( $attachments as $attachment )
    if ($attachment->post_title == $programme) {

        echo the_attachment_link($post->ID, false);
        break;
    }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)