0

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...

1
  • What you mean by indexes? Be some more clear pls. Do you want result in associative indexing mode? Commented Jul 18, 2012 at 6:44

3 Answers 3

1

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...

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your reply i want put Input text for answer values of each question and then i get the answer and submit qno and answervalues to answer table ?
0

You can use function mysql_fetch_array which return indexed and associative array.

Comments

0

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];

?>

1 Comment

thanks for your reply i want put Input text for answer values of each question and then i get the answer and submit qno and answervalues to answer table ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.