1.11M Members

Making a field in mysql in a link

 
0
 

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....

 
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>';
 
0
 

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>';
Question Answered as of 1 Year Ago by EvolutionFallen and AleMonteiro
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article