Click here to Skip to main content
15,446,510 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to echo a hyperlink with variables but the result is that I cannot click the link, its just normal text.
For context, this is a field contained in a table's column generated from a mysql_fetch_assoc loop.


PHP
echo '<a href="users.php?cl='.$row['client'].'">'.get_row_val("users","id",$row['client']).'</a>' ;


PHP
get_row_val("users","id",$row['client'])
Is just supposed to return the "user name".

This is what I get in html:

HTML
user name<a href="users.php?cl=58"></a>


This is what I am expecting to normally get:
HTML
<a href="users.php?cl=58">user name</a>


Any idea why this is happenning, is it a problem with the way I concatenate the strings and variables?

Thanks for your help.
Posted
Updated 13-Aug-11 1:46am
v3
Comments
Peter_in_2780 13-Aug-11 7:40am    
Please have a good look at you cut'n'paste code and edit the question to get it right. The echo you give says users.php?user= but your correct and incorrect outputs say users.php?cl= . Also, are you clearing server and browser caches as you are testing?

1 solution

This is just a guess because you haven't shown the source of the get_row_val function, but it looks like get_row_val outputs the name (using echo, printf, etc.) and does not return it.

This means that the echo from inside the function would happen first, then the string would be be built with an empty link - which would then be echoed after the "user name" string.
 
Share this answer
 
Comments
Hellik 13-Aug-11 14:53pm     CRLF
That's correct, here's the function, it made it to get the user name from the user id. function get_row_val($table, $label, $value) { $oMySQL = new MySQL(); $query = "SELECT * FROM `$table` WHERE `$label` = $value"; $oMySQL->ExecuteSQL($query); $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { echo ($row['first_name']." ".$row['sec_name']); } } Edit: Thanks I figured it out thanks to your guess. I modified the get row val function works now: function get_row_val($table, $label, $value) { $oMySQL = new MySQL(); $query = "SELECT * FROM `$table` WHERE `$label` = $value"; $oMySQL->ExecuteSQL($query); $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)) { return ($row['first_name']." ".$row['sec_name']); } }
Manfred Rudolf Bihy 13-Aug-11 15:58pm     CRLF
Excellent! 5+ Liquid Nitrogen
Peter_in_2780 13-Aug-11 18:30pm    
Good catch! I was waiting for a response to my comment on the original question...(and I probably wouldn't have twigged anyway)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900