Please let me know how to writte the below code so as to work because as it is it doesn't work
echo "<a href='$row['url']'>$row['link_text']</a>";
You are using '
twice, so you need to escape them or just remove them in this case:
echo "<a href='$row[url]'>$row[link_text]</a>";
This will work:
echo "<a href='".$row['url']."'>".$row['link_text']."</a>";
Also this:
echo "<a href='{$row['url']}'>{$row['link_text']}</a>";
It's personal preference.
It's because you've put a '
inside another '
.
echo "<a href='{$row['url']}'>{$row['link_text']}</a>";
or
echo "<a href='" . $row['url'] . "'>" . $row['link_text'] . "</a>";
Choose the one more to your liking.
When you have to insert complex variables like array values inside strings, usually printf
or sprintf
is more clear and less error-prone.:
printf("<a href='%s'>%s</a>", $row['url'], $row['link_text']);
Write so you can read it next time. Also syntax highlight is better this way:
echo '<a href="' . $row['url'] . '">' . $row['link_text'] . '</a>';
You can try with.
echo "<a href='".$row['url']."'>".$row['link_text']."</a>";
Or
echo "<a href='{$row['url']}'>{$row['link_text']}</a>";
Or
echo '<a href="'.$row["url"].'">'.$row["link_text"].'</a>';