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....
Related Article: mysql and php dynamic checkbox output
is a PHP discussion thread by akgeek that has 1 reply, was last updated 1 year ago and has been tagged with the keywords: php, mysql, checkbox, output, format.
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