2015-02-12 109 views
0

我能夠從我的數據庫中獲取數據並使用php顯示它們。 我想知道如何獲取包含數據的表的列名稱?或者是否有其他方法可以用來將親友的姓名與親屬姓名一起顯示?提取列表名稱

在此刻我緩存表中這樣說:

<?php 
$connection = mysql_connect('x ', 'x ', ' x'); 
mysql_select_db('x'); 

$query = "SELECT * FROM trip"; 
$result = mysql_query($query); 
echo "<table >"; 
while($row = mysql_fetch_array($result)){ 
if ($row['Day'] == date("Y-m-d")) 
{ 
echo '<tr class="today">'; 
} 
else {echo "<tr>";     } 
echo "<td>" . $row['Day'] . "</td> 
<td>" . $row['Country'] . "</td> 
<td>" . $row['Place'] . "</td> 
<td>" . $row['Flight'] . "</td> 
</tr>"; //$row['index'] the index here is a field name 
} 
echo "</table>"; //Close the table in HTML 
mysql_close(); //Make sure to close out the database connection 
?> 
+0

您使用的是什麼查詢?你在你的select語句中指定了列名,還是使用'*'? – 2015-02-12 01:52:58

+0

另一種方法是使用你現在擁有的東西,通過assoc獲取,然後得到這些數組鍵,或者是最直接的方式'DESCRIBE',然後獲取。 – Ghost 2015-02-12 01:57:15

+0

問題更新 – gigi 2015-02-12 02:12:48

回答

0

你可以使用Chris的答案使用mysql_函數,也可以運行實際查詢。

SHOW COLUMNS FROM mydb.mytable;