-3

朋友们,我是创建数据库的初学者,我正在使用 xampp 创建数据库

<html>
<body>
<marquee behavior="alternate">welcome</marquee>
</body>
</html>
<?php 
$username = "root";
$password = "root123";
$hostname = "localhost"; 
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>
<?php
$selected = mysql_select_db("missensencemuttation",$dbhandle) 
or die("Could not select missensencemuttation");
?>
<?php
$result = mysql_query("SELECT * FROM `primary_data` LIMIT 0, 30");
($row=mysql_fetch_array($result)); 
{
echo "disease_name:".$row{'disease_name'}." gene_name:".$row{'gene_name'};
}
?>enter code here
<?php
mysql_close($dbhandle);
?>

这就是我为将我的数据库与 php 连接所做的事情

但结果我只能看到我的表的第一行,其中有 10 行。但是当我用来连接它们时,我只能看到我的第一行。在我的 php

任何人都可以帮助我在 php 中连接我的所有数据吗?

<html>
<body>
<marquee behavior="alternate">welcome to the database</marquee>
<table border="3" align="center">
<tr><th>disase_name</th><th>gene_name</th></tr>      
<?php 
        $username = "root";
        $password = "2991";
        $hostname = "localhost"; 
        $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to   connect to MySQL");
        echo "Connected to MySQL<br>";
        $selected = mysql_select_db("disease",$dbhandle) or die("Could not select  disease");
        $result = mysql_query("SELECT * FROM `primary_data` LIMIT 0, 30");
        while($row = mysql_fetch_array($result))
        {
            echo "<tr><td>".$row['disease_name']."</td><td>".$row['gene_name']."</td>   </tr>";
        }
        mysql_close($dbhandle);
    ?>
    </table>    
    </body>
    </html>

我期望朋友的答案带有此代码

4

2 回答 2

1

您可以使用 while 循环来遍历已返回的所有结果。每mysql_fetch_array(),MySQL结果跳转到下一条记录。

您可以使用以下代码循环遍历所有行

while($row=mysql_fetch_array($result))
{
    echo "disease_name:".$row['disease_name']." gene_name:".$row['gene_name'];
}

您的完整代码如下所示:

<html>
    <body>
    <marquee behavior="alternate">welcome</marquee>
        <?php 
            $username = "root";
            $password = "root123";
            $hostname = "localhost"; 
            $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
            echo "Connected to MySQL<br>";

            $selected = mysql_select_db("missensencemuttation",$dbhandle) or die("Could not select missensencemuttation");
            $result = mysql_query("SELECT * FROM `primary_data` LIMIT 0, 30");
            while($row = mysql_fetch_array($result))
            {
                echo "disease_name:".$row['disease_name']." gene_name:".$row['gene_name'];
            }
            mysql_close($dbhandle);
        ?>
    </body>
</html>

感谢 Edwin Alex 对分号的评论

于 2013-03-19T12:20:15.123 回答
0

用户"["在这里。

echo "disease_name:".$row['disease_name']." gene_name:".$row['gene_name'];

你也应该循环它并显示。

while($row=mysql_fetch_array($result)) 
{
 echo "disease_name:".$row['disease_name']." gene_name:".$row['gene_name'];
}
于 2013-03-19T12:19:30.337 回答