2012-07-18 56 views
0

你好我取出由MySQL数据库中的数据,我想获得的列的索引表中的我怎样才能从MySQL查询与PHP的索引值?

<?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列i'e诺和titile我想显示在输出页面标题

在此先感谢...

+0

您可以通过索引的意思?请更清楚一点。你想要结果索引模式? – 2012-07-18 06:44:13

回答

1

请试试这个..

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

我希望它帮你....

,如果你有什幺问题,让我知道...

+0

感谢您的回复 – Venkat 2012-07-18 06:59:54

+0

感谢您的回复我希望把每个问题的答案值的输入文本,然后我得到答案并提交qno和answervalues来回答表? – Venkat 2012-07-18 09:16:57

0

试试这个;

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

?> 
+0

感谢您的回复我希望把每个问题的答案值的输入文本,然后我得到的答案和提交qno和answervalues回答表? – Venkat 2012-07-18 09:15:17

0

您可以使用函数mysql_fetch_array其返回索引和关联数组。