<a href> problem in PHP

They have: 105 posts

Joined: Mar 2006

I can to make links from the userid and name in browse users results, but I don't understand why I can't make a href links anywhere within other PHP code even if I use the same syntax as I have used for mysql_fetch_array. Why is this?

I have tried the following, but having spent a long time moving 's and "s I posted this question

echo "a href="send_message.php?sendto='.$row->userid."'> ".$row->userid."";

or

echo "a href="send_message.php?sendto='.$row['userid']."'> ".$row['userid']."";

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

You are missing some HTML tag information, this should work:

<?php
echo '<a href="send_message.php?sendto=' . $row['userid'] . '">' . $row['name'] . '</a>';
?>

I am pretty sure you are fetching the rows as an array, so you access the user id with $row['userid'], not $row->userid.

You may want to look over the PHP manual page on Strings for more information on echoing strings as well as concatenation.

They have: 105 posts

Joined: Mar 2006

I tried that, and then I realised that the userid for the user profile that is being viewed by the logged in user, is passed with a link using view_profile.php?id=userid, does this mean I can use something like the following?

echo 'a href="send_message.php?sendto=' . userid='$_GET[id] . '">' . userid='$_GET[id] . '';

Also, it's not using a mysql_fetch_array on this page, so not sure what the other ways to write this string. I looked at the link for PHP strings but there is nothing about a href and strings there.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.