0

我有以下问题,我有一个包含以下列的 mysql 表,

-name
-address
-zipcode
-etc.

我在我的 php 代码中有一个像这样的表:

<table class="listing" cellpadding="0" cellspacing="0">
                <tr>
                    <th>Company name</th>
                    <th>Adress</th>
                    <th>Zipcode</th>
                    <th>more</th>
                    <th>more</th>

                    <th>more</th>
                    <th>more</th>
                    <th>more</th>
                </tr>
            </table> 

我想要的是,当有人创建一家公司时,它将显示一行来自 mysql 的数据,就像这样:

公司地址 邮编
1 1 1
2 2 2

有人能帮我吗?

编辑:

一些额外的代码:

    <div id="center-column">
      <div class="select-bar">
               Bedrijven:
            </div>
            <div class="table">
                <table class="listing" cellpadding="0" cellspacing="0">
                    <tr>
                        <th>Company name</th>
                        <th>Adress</th>
                        <th>Zipcode</th>
                        <th>more</th>
                        <th>more</th>

                        <th>more</th>
                        <th>more</th>
                        <th>more</th>
                    </tr>
                </table>
            </div>
            <div class="table">
            </div>
        </div>
        <div id="right-column">
            <strong class="h">Info</strong>
            <div class="box"><strong>Gebruikersnaam:</strong> <?php echo $naam ?><br />
            </div>
        </div>
    </div>
    <div id="footer"></div>
</div>
</body>
</html>
<?php else : ?>
4

1 回答 1

0

使用以下代码:(更改为您的需求:localhost、USERNAME、PASSWORD、DATABASE_NAME、TABLE_NAME、TABLE_ROW)

$con = mysqli_connect('localhost','USERNAME','PASSWORD','DATABASE_NAME');
if (!$con)
    {
    die('Could not connect: ' . mysqli_error($con));
    }
$sql = "USE DATABASE_NAME";
$sql = "SELECT * FROM TABLE_NAME";

$result = mysqli_query($con,$sql)
    or die("Error: " . mysqli_error($con));

echo "<table border='0'>";
while ($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . 'Company: ' . "<b>" . $row['TABLE_ROW'] . "</b>" . ' | Address: ' . "<b>" . $row ['TABLE_ROW'] . "</b>" . ' | Zipcode: ' . "<b>" . $row ['TABLE_ROW'] . "</b>" . "</td>";
    echo "</tr>";
    } 
echo "</table>";
?>

如果您有更多问题或它不起作用,请告诉我,我会尽力提供帮助。

于 2013-09-06T07:45:11.670 回答