2013-10-28 67 views
0

所以我的目標是將兩個數據打印到一個標準表中。從兩張表打印數據

理想情況下,它應該顯示每個不同的獎學金名稱和它的表與所有申請它的學生列表。我不確定我的方法是否正確。

請幫助,我想學習的基礎知識。提前致謝。

<?php 
include_once 'function.php'; 
connect(); 

?> 
<html><body> 

<?php 

$query = "SELECT * 
FROM entry, student_details 

WHERE entry.user_id=student_details.user_id"; 

//run query 
$result = mysql_query($query); 
// creating a table 


echo "<table border='1'> 
<tr> 
<th>Student ID</th> 
<th>Student Name</th> 

</tr>"; 

//Print the record that matches the criteria of the query 
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
echo $row['s_name'] 
{ 
echo "<tr>"; 
echo "<td>" . $row['student_id'] . "</td>"; 
echo "<td>" . $row['student_name' ] . "</td>"; 
echo "</tr>"; 

} 
} 
?> 

</table> 
<?php close() 
?> 
</body></html> 

錯誤我得到的是這樣解析錯誤:行echo "<tr>";

回答

0

語法錯誤,意想不到的「迴響」(T_ECHO)你有一個語法錯誤。

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
echo $row['s_name']; 

echo "<tr>"; 
echo "<td>" . $row['student_id'] . "</td>"; 
echo "<td>" . $row['student_name' ] . "</td>"; 
echo "</tr>"; 

} 
+0

而且,語法錯誤是?我知道它在哪裏,但你沒有指出OP在哪裏犯了這個錯誤。你所做的只是粘貼OP的代碼。 –

+0

在那裏的語法錯誤有太多的開始和結束括號。我發佈的代碼是剛刪除它 –

1

解析錯誤消息不一定上註明實際的行數,但很多時候來源於上面一行是這樣的:

echo $row['s_name'] 
-------------------^ 
// missing semi-colon 

你忘了在結束分號結束。

修改它看起來像這樣:

echo $row['s_name']; 
-------------------^ 
+0

謝謝弗雷德..錯誤是沒有辦法.. 但我不能看到任何數據打印。只是表頭 – user2897131

+0

@ user2897131不客氣。嘗試將這個'WHERE entry.user_id = student_details.user_id''改爲'WHERE entry.user_id ='student_details.user_id'''看看它是否會啓動。 –

+0

@ user2897131另一件事,this'<?php close() ' - 是你的一個包含文件中的函數嗎?它可能也應該有這樣的結束分號,但不是100%肯定'<?php close();' –