unsider Posted March 14, 2008 Share Posted March 14, 2008 I currently am trying to create a more interconnected site, and what better way to do that than to have a link to that particular user's profile than when he submits a comment. The link to his profile will be in in his username, I'm sure you've all seen a system that works this way. <a href="example.com/main/index.php?userinfo=$displayed username">$displayed username</a> Excerpt from code, but it's all that is necessary. <?php $query = "SELECT id, commenttext, username FROM comments LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); echo '<table div class="tborder">'; $username = $_SESSION['username']; while($row = mysql_fetch_array($result)) { echo '<tr class="tr' . $tr . '"><td>' . '<img src="http://example.com/main/images/post.gif">' . '<a href="userinfo.php?user=$username">' . $row["username"] . '</a>' . '<br>' . ' posted on: ' . '<br><br>' . ' ' . $row["commenttext"] . '</td></tr>'; // etc.... ?> NO ERRORS, but this is the URL it displays: http://example.com/main/userinfo.php?user=$username Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/96196-linking-sessions-help/ Share on other sites More sharing options...
pocobueno1388 Posted March 14, 2008 Share Posted March 14, 2008 It's because you are using single quotes instead of double. Try this: <?php $query = "SELECT id, commenttext, username FROM comments LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); echo '<table div class="tborder">'; $username = $_SESSION['username']; while($row = mysql_fetch_array($result)) { echo '<tr class="tr' . $tr . '"><td>' . '<img src="http://example.com/main/images/post.gif">' . "<a href='userinfo.php?user=$username'>" . $row["username"] . '</a>' . '<br>' . ' posted on: ' . '<br><br>' . ' ' . $row["commenttext"] . '</td></tr>'; ?> Link to comment https://forums.phpfreaks.com/topic/96196-linking-sessions-help/#findComment-492444 Share on other sites More sharing options...
uniflare Posted March 14, 2008 Share Posted March 14, 2008 you must concatenate variables into strings with the literal single quote. Single quote strings are Literal (Meaning anything inside will stay as-is and wont call functions/variables etc without concatenation) All Double Quote strings are Dynamic/Variable (dont know the exact name :/) can use specific functions/variables without concatenating. hope this helps, Link to comment https://forums.phpfreaks.com/topic/96196-linking-sessions-help/#findComment-492450 Share on other sites More sharing options...
unsider Posted March 14, 2008 Author Share Posted March 14, 2008 Thanks all, it does help, and that was the problem Link to comment https://forums.phpfreaks.com/topic/96196-linking-sessions-help/#findComment-492459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.