0

I feel pretty stupid for asking this one, I want to paste 'id' that I retrieve from database, which is stored in $link variable into the <a href> tag after details=...>Read More.., but I can't seem to get it to work.

<p>
    <?php 

    $longString = $row['name'];
    $link = $row['id'];

    echo readMoreHelper($longString);

    function readMoreHelper($story_desc, $chars = 100) {
        $story_desc = substr($story_desc,0,$chars);  
        $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
        $story_desc = $story_desc." <a href='details.php?details=$link>Read More...</a>";  
        return $story_desc;  
    } 

    ?> 
</p>

1 Answer 1

2

You need to pass $link as a function parameter.

You also left out the ' at the end of the href attribute.

echo readMoreHelper($longString, $link);

function readMoreHelper($story_desc, $link, $chars = 100) {
    $story_desc = substr($story_desc,0,$chars);  
    $story_desc = substr($story_desc,0,strrpos($story_desc,' '));  
    $story_desc .= " <a href='details.php?details=$link'>Read More...</a>";  
    return $story_desc;  
} 
Sign up to request clarification or add additional context in comments.

3 Comments

thanks, I guess it's bed time since I failed to solve this one on my own.
@user14584183 If it's a good answer check it solve.
Ok! I doesn't have ask a question yet. 😊 Happy coding!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.