Click here to Skip to main content
Rate this: bad
good
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
Hellik234
Edited 13-Aug-11 1:46am
v3
Comments
Peter_in_2780 at 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 at 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 at 13-Aug-11 15:58pm
   
Excellent! 5+
 
Liquid Nitrogen
Peter_in_2780 at 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
0 OriginalGriff 510
1 Prakriti Goyal 255
2 Yogesh Kumar Tyagi 224
3 Maciej Los 195
4 CPallini 180
0 OriginalGriff 6,632
1 Sergey Alexandrovich Kryukov 5,429
2 Maciej Los 3,474
3 Peter Leow 3,309
4 DamithSL 2,495


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 13 Aug 2011
Copyright © CodeProject, 1999-2014
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