Skip to content Skip to sidebar Skip to footer

Issue With Using Php Variable In Hyperlink

How do you use one php variable for the url in a hyperlink around another php variable? Below is my code, which is clearly not working. I want $url to be the hyperlinked text of $s

Solution 1:

You are not concatenating your strings properly.

for($i=0; $i < $numberOfRows; $i++) {
        $row = $result->fetch_assoc();
        echo'<tr>';
        echo'<td>' . $row['artistName'] . '</td>';
        echo'<td><a href="' . $row['url'] . '" >' . $row['songTitle'] . '</a></td>';
        echo'<td>' . $row['yOR'] . '</td>';
        echo'</tr>';
    }

Solution 2:

did you copy your script from somewhere? In parts of it you seem to understand how to escape and use PHP values inside a string, but then you messed up the one line.

Anyway, this is it fixed.. you didn't have your quotes or single quotes used properly.

echo "<td><a href='". $row['url'] . "'>" . $row['songTitle'] ." </a> </td>";

Post a Comment for "Issue With Using Php Variable In Hyperlink"