[英]How can i get the index value from the MySQL query with php?
嗨,我正在從mysql數據庫中獲取數據,我想獲取表中各列的索引
<?php
//connects to database
$con = mysql_connect("locahost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("appulentoweb", $con);
//retrieve data from database
$result = mysql_query("SELECT * FROM questions");
?>
我想獲取表中各列的索引,然后將在屏幕上顯示該數據。
在表中我有2列,即qno和titile,我想在輸出頁面中顯示標題
提前致謝...
請嘗試這個。
<?php
//connects to database
$con = mysql_connect("locahost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("appulentoweb", $con);
//retrieve data from database
$result = mysql_query("SELECT * FROM questions"); ?>
<table>
<tr>
<th> Question no</th>
<th> Question </th>
</tr>
<?php
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['qno'];?></td>
<td><?php echo $row['question'];?></td></tr>
<?php } ?>
</table>
希望對您有所幫助。
如果您有問題,請告訴我...
嘗試這個;
<?php
//connects to database
$con = mysql_connect("locahost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("appulentoweb", $con);
//retrieve data from database
$result = mysql_query("SELECT * FROM questions");
$rows = mysql_fetch_array($result, MYSQL_ASSOC);
echo $rows['qno'];
echo $rows['title'];
要么
$rows = mysql_fetch_array($result, MYSQL_NUM);
echo $rows[0];
echo $rows[1];
?>
您可以使用函數mysql_fetch_array返回索引數組和關聯數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.