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. Quote Link to comment 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>'; ?> Quote Link to comment 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, Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.