Solved

echo url from database query

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

776 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