Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

echo url from database query

Hello Experts,
I hate that I have to post this question but I just can't get it right... I have a databse that  has a table called lmenu. In that table I have two fields called link_name and url
I am trying to construct an echo stmt that will dispay the link with the value for every thing in the database matching the id

Here is my code..


do {
echo '<a href=" . $row[\'url\'] . \">\' . $row[\'link_name\'] . "</a>';
echo "<br>";
echo "<p>";
}while($row = mysql_fetch_array($result));

What am I missing here to make it work
echo '<a href=" . $row[\'url\'] . \">\' . $row[\'link_name\'] . "</a>';

This is what is echo'd to the screen

' . $row['link_name'] . "


Thanks, Dan

0
dk4210
Asked:
dk4210
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
try it like this:

echo '<a href="' . $row['url'] . '">' . $row['link_name'] . '"</a>';
0
 
dr_dedoCommented:
u use back slash to escap a character that php parser would consider as something of its language, so, when i want to write this

this quates " eclose strings in PHP

i do it this way
echo "this quates \" eclose strings in PHP";

becasue i can't write it this way or else php will produce an error
echo "this quates " eclose strings in PHP";

but, i don't escape variable quotes, or else PHP won't get them as variables and produce an error
echo '<a href=" . $row[\'url\'] . \">\' . $row[\'link_name\'] . "</a>';

you can write it the way angel did or do it like this
echo "<a href=\"{$row['url']}\">{$row['link_name']}</a>";

{} eclosing a variable in a douple quated string (string enclosed by " )   {} will force php to parse what is between these curly brakets as a variable
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now