Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

echo url from database query

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

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 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