-2

我正在写我的社交网络,当帖子显示在新闻源上时,个人资料图片和作者姓名将不会显示。这是我的代码:

$owner_id=mysql_result($result,$i,"post_owner_id"); //Post writer's user ID
$content=mysql_result($result,$i,"content"); //Content of the post
$date=mysql_result($result,$i,"date"); //Date
$time=mysql_result($result,$i,"time"); //Time
$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = '" . $owner_id . "'"); //MYSQL query to get the information of the post writer using user ID
$post_firstname=mysql_result($poi_query, 0, "firstname"); //Writer's first name
$post_lastname=mysql_result($poi_query, 0, "lastname"); //Writer's Last name
$post_profile_picture=mysql_result($poi_query, 0, "profile_picture"); //Writer's profile picture
?>

      <div class="post">
        <h1 class="post-title"><a href="profile.php?user=<?php echo $owner_id; ?>"> <?php echo $post_firstname; ?> <?php echo $post_lastname; ?></a></h1>
        <p class="content"><?php echo $content; ?></p>
        <p class="details"><?php echo $date; ?> at <?php echo $time; ?></p>
        <br/><hr/><br/>
      </div>

除了名称和图片外,其他一切都很好。有什么帮助吗?我几乎肯定它与 poi_query 有关......顺便说一句,如果我手动输入用户 ID,所有代码在终端中都可以正常工作。

配置公司:

<?php

$hostname = 'localhost';        // Your MySQL hostname. Usualy named as 'localhost', so you're NOT necessary to change this even this script has already online on the internet.
 $dbname   = 'social-network'; // Your database name.
 $username = 'root';             // Your database username.
 $password = '********';                 // Your database password. If your database has no password, leave it empty.

// Let's connect to host
 mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
 // Select the database
 mysql_select_db($dbname) or DIE('Database name is not available!');

?>
4

3 回答 3

0

我唯一能看到的可能是从 owner_id 中删除引号?

$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = " . $owner_id);
于 2012-04-13T03:35:05.697 回答
0

更改此行:

$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = '" . $owner_id . "'");

到:

$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = '" . $owner_id . "'") or die(mysql_error());

查看您是否收到有关来自 MySQL 的查询的错误消息。

编辑:

这里的问题最终是一个mysql_close();干扰$poi_query分配的呼叫。

于 2012-04-13T03:40:08.217 回答
-1

尝试

$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = " . $owner_id) or die(mysql_error());

或尝试转储变量以查看它给出了什么

var_dump($poi_query);

这将帮助您缩小问题范围

于 2012-04-13T03:42:53.133 回答