Здравствуй,
Что случилось с моей функцией? Кажется, это не работает, но я не знаю, почему. Функция должна возвращать имя пользователя:
function getusername($username) {
$sql = "SELECT username FROM users WHERE id='".$username."' LIMIT 1";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);
return $row['$username'];
Когда я использую его в этом коде, он ничего не возвращает:
if (mysql_num_rows($res) == 1) {
echo "<table width='100%'>";
//Check to see if the person accessing this page is logged in
if (isset($_SESSION['username'])) { echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location = 'post_reply.php?cid=".$cid."&tid=".$tid."'\" />
"; } else { echo "<tr><td colspan='2'>Please log in to add your reply.
</td></tr>"; }
//Fetch all the topic data from the database
while ($row = mysql_fetch_assoc($res)) {
//Query the posts table for all posts in the specified topic
$sql2 = "SELECT * FROM posts WHERE category_id='".$cid."' AND topic_id='".$tid."'";
//Execute the SELECT query
$res2 = mysql_query($sql2) or die(mysql_error());
//Fetch all the post data from the database
while ($row2 = mysql_fetch_assoc($res2)) {
//Echo out the topic post data from the database
echo "<tr><td valign='top' style='border: 1px solid blue;'><div style='min-height: 125px;'>".$row['topic_title']."
by ".getusername($row2['post_creator'])." - ".convertdate($row2['post_date'])."
".$row2['post_content']."</div></td><td width='200' valign='top' align='center' style='border: 1px solid blue;'>User Info Here</td></tr><tr><td colspan='2'>
</td></tr>";
}