2012-04-13 38 views
-2

我正在編寫我的社交網絡,當新聞源顯示帖子時,個人資料圖片和作者姓名不會顯示。這裏是我的代碼:MYSQL代碼不拉信息

$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,所有代碼在終端中都能正常工作。

Config.inc:

<?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!'); 

?> 
+0

請張貼線路,其中要包括該配置.inc文件中的原始PHP腳本。 – kjones 2012-04-13 04:06:32

回答

0

改變這一行:

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

到:

看到,如果你正在接受有關從MySQL查詢錯誤消息。

編輯:

問題就在這裏結束了作爲一個呼叫mysql_close();這是與$poi_query分配干擾。

0

我能看到的唯一的事,也許是刪除從owner_id引號?

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

沒有。沒有工作。 – 2012-04-13 03:37:23

+1

您是否嘗試回顯$ owner_id,以確保它不會空白? – 2012-04-13 03:40:04

+0

@CassieCarter這也是一個好主意,以確保'$ owner_id'是您在將它提供給查詢語句時所期望的。 – kjones 2012-04-13 03:41:39

-1

嘗試

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

或嘗試傾銷變量,看看它給

var_dump($poi_query); 

這將有助於你縮小問題