Extracting data from mysql using php and using in html <a> tag

Hi,
As part of a course I’m enrolled on, I have to extract first names($first_name) and last names($last_name) from a mysql database using php. I then have to display them as hyperlinks (in a html table) that links to a page(view.php) that displays the users’ individual details using the profile id ($profile_id) as a GET response.

I can extract the data and link to view.php but I cannot get the variable values to display as hyperlink text. Instead it displays as code eg: “htmlentities((”$trow[“first_name”]".$trow[“last_name”]))".

Over the past 3 days I have tried various combinations of single and double quotes with concatenation, read php documentation and combed the web to no avail. Its driving me crazy and any help would be much appreciated.

Here is the line of code:

echo ('<a href="view.php?profile_id='.$trow['profile_id'].'">htmlentities(("$trow["first_name"]".$trow["last_name"]))</a>');

You could try:

echo ('<a href="view.php?profile_id='.$trow['profile_id'].'">'.htmlentities($trow['first_name'].' '.$trow['last_name']).'</a>');
1 Like

Ah man, I was hoping you’d pick this up. Thank you so much. That works perfectly. I must say I’m struggling to properly understand string interpolation and concatenation when it comes to variables. I thought that to expand variables in a string we had to use double quotes?
After viewing the following code parsed by the browser:

echo ('<a href="view.php?profile_id='.$trow['profile_id'].'">test</a></br>');
echo ('<a href="view.php?profile_id='.$trow['profile_id'].'">'.htmlentities($trow['first_name']).' test1</a></br>');
echo ('<a href="view.php?profile_id=1">test2</a></br>');
echo ('<a href="view.php?profile_id='.$trow['profile_id'].'">'.'</a>1</br>2</br>3</br>4');

I can see that echo ('<a href="view.php?profile_id=">test</a>') is the actual html string with ?profile_id used to pass the $_GET array. With the strings '.$trow['profile_id'].' and '.htmlentities($trow['first_name'].' and '.$trow['last_name']).' inserted/concatenated into it.
I must say I am struggling to properly understand string interpolation and concatenation when it comes to variables. I thought that to expand variables in a string we had to use double quotes?

Thanks again.