doucepei5298 2012-10-21 18:52
浏览 23

PHP仅显示来自数据库的单个结果

So I've been working on a small system which involves codes which is used for a user to redeem them for some sort of reward.

So far I have this script in PHP and HTML: http://pastebin.com/UUsEKpev

It's only showing one result which you can see here, I want it to display multiple results in a table going down showing all results.

<?php

$yn;
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("mcv") or die(mysql_error());

$result = mysql_query("SELECT * FROM Codes")
or die(mysql_error());  

$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

if ($row['Used'] == 1) {
    $yn = "Yes";
}
else{
    $yn = "No";
}

?>

<html>
<head>
    <title>Minecraft Codes</title>
    <style type="text/css">

    tbody {
        display: table-row-group;
        vertical-align: middle;
        border-color: inherit;
    }

    tr {
        display: table-row;
        vertical-align: inherit;
        border-color: inherit;
    }

    th {
        border: 1px solid #C3C3C3;
        padding: 3px;
        vertical-align: top;
        width: 20%;
        background-color: #E5EECC;
    }

    table.reference {
        background-color: white;
        border: 1px solid #C3C3C3;
        border-collapse: collapse;
        width: 50%;
    }

    table.reference td {
        border: 1px solid #C3C3C3;
        padding: 3px;
        vertical-align: top;
        width: 20%;
    }

    table, th, td, input, textarea {
        font-size: 100%;
    }

    body, p, h1, h2, h3, h4, table, td, th, ul, ol, textarea, input {
        font-family: verdana,helvetica,arial,sans-serif;
    }

    </style>
</head>

<body>
    <center>
        <br />
        <h1><u>Minecraft Server VIP Codes</u></h1>
        <br />

        <table class="reference">
            <tr>
                <th>Code</th>
              <th>Used?</th>
          </tr>
          <?php echo "<tr><td>".$row['Code']."</td><td>".$yn."</td></tr>"; ?>
        </table>
    </center>
</body>
</html>
  • 写回答

3条回答 默认 最新

  • doujin8476 2012-10-21 18:55
    关注

    Well yes, you call mysql_fetch_row() only a single time, thus you only retrieve a single row. You have to wrap that into a loop that is executed as many times as there are rows.

    There are millions of examples on the internet that you can learn from...

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计