Click here to Skip to main content
12,300,379 members (52,747 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP
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.


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

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

This is what I get in html:

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

This is what I am expecting to normally get:
<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 13-Aug-11 1:15am
Hellik292
Edited 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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Hellik 13-Aug-11 14:53pm
   
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 R. Bihy 13-Aug-11 15:58pm
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 13 Aug 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100