在php中的表中显示数量字段

时间:2014-04-30 15:26:03

标签: php

我试图让我的桌子看起来像这样

http://gyazo.com/6a134b723c30e97fa99559158cde4b1e

但是当我使用我的代码时就像这样

http://gyazo.com/1c08f83e744b3a20c99b55eee5313045

我无法获得数量字段或添加字段来为我的生活工作;数量字段只是空白。我非常感谢一些帮助,因为我无法让它发挥作用。

            <?php require_once("include/db_connect.php"); ?>
            <html>
            <head><title>Displaying Image files using PHP</title></head>
            <body>
            <h1>Displaying Images from an Image table using PHP</h1>

            <?php


            $db_link = db_connect("project");

            // Retrieve table properties

            $fields = mysql_list_fields("project", "bookstore");
            $num_columns = mysql_num_fields($fields);

            // Make a simple database query to select all columns and rows

            $query = "SELECT * FROM bookstore";
            $result = mysql_query($query) or die("SQL query failed");

            // Display results as an HTML table. Note how mysql_field name
            // uses the $fields object to extract the column names

            echo '<table border="1" cellpadding = "5" >';

            // Display the column names

            echo "<tr>";
            for ($i = 0; $i < $num_columns; $i++)
            {
               echo "<th>", mysql_field_name($fields, $i), "</th>";
            }

                  echo "<th>"Quantity "</th>";

            echo "</tr>";

            // Loop over the rows of the table.
            // $row contains the information for each row
            // Refer to the names of the fields in the table
            // Must ahow the path where the image files are held

            while ($row = mysql_fetch_assoc($result))
            {
               echo "<tr>
               <form action='somethingToHandleForm.php' method='post'>";

               echo "<td>". $row['isbn']. "</td>";
               echo "<td>". $row['title']."</td>";
               echo "<td>". $row['author']."</td>";
               echo "<td>". $row['pub']."</td>";
               echo "<td>". $row['year']."</td>";
               echo "<td>". $row['price']."</td>";
               echo "<td><input type='text' name='quantity' value=".$row['quantity']."/></td>";
               echo "<td><input type='submit' value='add></td>";
               echo "</form>";

               echo "</tr>";

            }
            echo "</table>";

            // Free the resources and close the connection

            mysql_free_result($result);
            mysql_close($db_link);
            ?>
            </body>
            </html>

2 个答案:

答案 0 :(得分:2)

我注意到的一件事是你在值= add之后错过了这一行中的单引号:

<input type='submit' value='add>

答案 1 :(得分:0)

HTML中存在一些格式问题,这些问题在呈现表格时会成为问题的根源。特别是这些行:

echo "<td><input type='text' name='quantity' value=".$row['quantity']."/></td>";
echo "<td><input type='submit' value='add></td>";

第一行的value属性未正确用引号括起来,并且第二行中的值add没有结束单引号(也没有关闭{{1标记),尝试以下方法:

input
相关问题