如何获取数据库的内容而不是索引


How can I get the content of my database and not the index

我成功地将数据插入我的MySQL数据库,但我的问题是我得到的结果和我在我的数据库中是索引而不是实际内容。我为我的php文件中的一个选项编写了以下代码。如何获取内容而不是索引?问题是在 SQL 语句还是在 PHP 代码中?例如,如果用户从弹出菜单中选择第一个选项,那么我将得到 No 1 而不是serviceType = "Database Type"

Finding ServiceType Title   RootCause   RiskRating  Impact  Efforts Likelihood  
1   2   gg  AC  1   1   1   1    gg  gg  gg 1
7   1   kkkk    Cfm 1   1   2   1    kkkkk   kkkkk   kkkkkk 1
    1
<?php
    mysql_select_db("ers_1", $con);
    $result = mysql_query("SELECT ServiceType_ID, ServiceType_Name FROM servicetype_lookup  ");
    while($row = mysql_fetch_array($result)) {
        $id = $row['ServiceType_ID'];
        $value = $row['ServiceType_Name'];
        echo "<option value='$id'>$value</option>";
    }
?>

请在 SQL 工具中检查您的查询,以确保您确实收到了该查询的数据。如果没有数据,则可能会导致您的问题。

此外,请使用:

while($row = mysql_fetch_assoc($result)) 

而不是

while($row = mysql_fetch_array($result)) 

在您的 while() 语句中获取您正在寻找的输出。

祝你好运!

作为一个想法,你需要考虑放弃mysql_命令,转而使用MySQLi和PDO库。

看这里:选择一个 MySQL API