Reputation: 1
Hi i am fetching the data from mysql data base i want get the index of the columns in the 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");
?>
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
Thanks in Advance...
Upvotes: 0
Views: 4709
Reputation: 3188
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...
Upvotes: 1
Reputation: 7752
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];
?>
Upvotes: 0
Reputation: 142
You can use function mysql_fetch_array which return indexed and associative array.
Upvotes: 0