Solved

echo url from database query

Posted on 2006-06-10
2
298 Views
Last Modified: 2013-12-12
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
Comment
Question by:dk4210
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 16878154
try it like this:

echo '<a href="' . $row['url'] . '">' . $row['link_name'] . '"</a>';
0
 
LVL 16

Assisted Solution

by:dr_dedo
dr_dedo earned 25 total points
ID: 16878433
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now