I have a string of text that is part of a URL on a PHP page that looks like this:.
<a href="http://www.adomain.com/links.php?EmpNo={{EMP_NO}}">LINK</a>
I need to replace the {{EMP_NO}} with a session variable I have created $SESSION['EmpNo']
The href is populated by a PHP function that queries the database and writes the href links depending on the userid.
function get_user_icons($user_id)
{
$icons = array();
$user_id = mysql_real_escape_string($user_id);
$sql = "SELECT ic.* "
. "FROM gbl_empicons AS em "
. "LEFT JOIN gbl_icons AS ic ON em.IconId = ic.id "
. "WHERE em.EmpNo = '$user_id' ORDER BY em.IconId";
$res = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($res))
{
$icons[] = $row;
}
return $icons;
}
Later the actual links are written out like this:
$icons = get_user_icons($row_WAATKgblqemplisting['EmpNo']);
foreach ($icons as $ic)
{
echo $ic['url'] . ' ';
}
I've tried to update this function with str_replace with no luck in both locations.
str_replace('{{EMP_NO}}', $_SESSION['EmpNo']);
This is not working. I have also tried to use the em.EmpNo to no avail. What is the best way to achieve this result?