[英]How can i get the index value from the MySQL query with php?
Hi i am fetching the data from mysql data base i want get the index of the columns in the table 嗨,我正在从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");
?>
i want get the index of the columns in the table then i will display that data in the screen. 我想获取表中各列的索引,然后将在屏幕上显示该数据。
in the table i have 2 columns i'e qno and titile i want display that titles in the output page 在表中我有2列,即qno和titile,我想在输出页面中显示标题
Thanks in Advance... 提前致谢...
please try this.. 请尝试这个。
<?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>
i hope that it is help you.... 希望对您有所帮助。
if you have nay problem let me know... 如果您有问题,请告诉我...
try this; 尝试这个;
<?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'];
OR 要么
$rows = mysql_fetch_array($result, MYSQL_NUM);
echo $rows[0];
echo $rows[1];
?>
您可以使用函数mysql_fetch_array返回索引数组和关联数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.