We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,134 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Making a field in mysql in a link

This is probably simple enough to do, but I cant get it!
I have a mysql table 'links' with these fields;

id int 10 primary ai
link varchar 200
description varchar 200

I have a links page to populate with this info. I want the desciption as the visible text.

This is my code which doesnt work!

 <?php 
                include 'connect.php';
                $data = mysql_query("SELECT * FROM links ORDER BY id DESC")
                or die(mysql_error());

                while($info = mysql_fetch_array( $data )) { 
                echo '<a href="$info['link']">$info['description']</a>';//this line is the problem
                echo '<br />';
                }
              ?> 

Can anyone see where im going wrong?

Thanks....

3
Contributors
2
Replies
1 Hour
Discussion Span
4 Months Ago
Last Updated
3
Views
Question
Answered
GlenRogers
Posting Whiz in Training
256 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I think it's just a syntax problem... It's been a while since I coded in PHP, but this should work:

echo '<a href="'.$info['link'].'">.'$info['description'].'</a>';
AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

AleMonteiro is correct. The way you originally put the variables in does not replace them with their values in the echo statement. If you want to stay with single quotes, you need to use the concatenation operator (.) as shown above. If you want to put the variable in without the concatenation operator, have to use double quotes around the entire string, escape the double quotes for the href, and since you're referring to array indexes you must add curly braces around the variables too:

echo "<a href=\"{$info['link']}\">{$info['description']}</a>';
EvolutionFallen
Posting Pro in Training
406 posts since Aug 2009
Reputation Points: 95
Solved Threads: 84
Skill Endorsements: 7
Question Answered as of 3 Months Ago by AleMonteiro and EvolutionFallen

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0741 seconds using 2.73MB