dongyong5912 2015-03-06 22:31
浏览 47

现在我需要将数据添加到数据库中以显示数据库

So I added a small table to a database for a small project per se. Now I need help pulling that data out and displaying it correctly.

Table info
        CREATE TABLE IF NOT EXISTS `tab_dimensions` (
        `id` int(11) NOT NULL,
        `length` int(11) NOT NULL,
        `height` int(11) NOT NULL,
        `width` int(11) NOT NULL,
        `offset` int(11) NOT NULL,
        PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

first piece of data I have

        INSERT INTO `tab_dimensions` (`id`, `length`, `height`, `width`,      `offset`) VALUES
        (56301, 600, 255, 183, 480);

So that is the basic layout of it. I have started with

    $sql = 'SELECT id, length, width, height, offset FROM tab_dimensions';

But am having trouble with what goes next. Sorry a newbie here trying to figure it out and learn.

Thanks in advance!

Update- I this is a existing DB that I am adding to so the connection is not needed it already has one as $db

I am trying to use this data to populate a mouseover image mapping, so I only need to pull data and then use my existing table to display it.

    <div id="hauler-pole" style="display:none;">
      <table border="0" width="300">
        <tr>
            <td><strong>front</strong></td>
            <td>Length: </td>
            <td>Width: </td>
            <td>Height: </td>
        </tr>
        <tr>
            <td colspan="4">&nbsp;</td>
        </tr>
        <tr>
            <td><strong>Rear</strong></td>
            <td>Length: </td>
            <td>Width: </td>
            <td>Height: </td>
        </tr>
      </table>
    </div>

So if i mouse over id# 56301 that data is displayed only in the table.

  • 写回答

1条回答 默认 最新

  • douxianglu4370 2015-03-06 22:38
    关注

    http://www.w3schools.com/php/php_mysql_select.asp

    <?php
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    $sql = "SELECT id, length, width, height, offset FROM tab_dimensions";
    $result = $conn->query($sql);
    
    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) {
            echo "id: " . $row["id"];
            echo "length: " . $row["length"];
            echo "width: " . $row["width"];
            echo "height: " . $row["height"];
            echo "offset : " . $row["offset"];
        }
    } else {
        echo "0 results";
    }
    $conn->close();
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作