やあ、
私の機能の何が問題になっていますか?機能していないようですが、理由はわかりません。この関数はユーザー名を返すはずです:
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."'\" /><hr />"; } else { echo "<tr><td colspan='2'><p>Please log in to add your reply.</p><hr /></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']."<br />by ".getusername($row2['post_creator'])." - ".convertdate($row2['post_date'])."<hr />".$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'><hr /></td></tr>";
}