Solved

echo url from database query

Posted on 2006-06-10
2
297 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
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…

757 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

23 Experts available now in Live!

Get 1:1 Help Now