简体   繁体   English

从MySQL结果生成的HTML表,以PHP形式处理

[英]HTML table generated from MySQL results, to process in a form with PHP

I have a simple MySQL database with some products (id, name, amount). 我有一些产品(id,名称,金额)的简单MySQL数据库。 The end result will be a PDF that has a page for every product (amount in database = default amount of how many pages of that product will be printed). 最终结果将是一个PDF,其中每个产品都有一个页面(数据库中的数量=将要打印该产品多少页的默认数量)。 Example: The database contains "1, Apples, 4". 示例:数据库包含“ 1,Apples,4”。 The end result will be a PDF that contains 4 pages with the word "Apples" on it. 最终结果将是一个PDF,其中包含4页,上面带有单词“ Apples”。 When I have 20 products in my database, the final PDF will contain all products with their respective 'page-amounts`. 当我的数据库中有20种产品时,最终的PDF将包含所有产品及其各自的“页面数量”。

I put all the products in a simple HTML table (in a form) with PHP. 我用PHP将所有产品放在一个简单的HTML表中(以表格的形式)。 The end-user must be able to change the amount of pages for a product for just one time. 最终用户必须只能一次更改产品的页面数量。 So if there is "1, Apples, 4" in the database, the user should be able to make it "1, Apples, 8" for just one time. 因此,如果数据库中有“ 1,Apples,4”,则用户应该只能将其设置为“ 1,Apples,8”。 My guess is to put the 'default' amount in an input value-tag, but I don't see how to process the form... 我的猜测是将“默认”金额放入输入值标签中,但我看不到如何处理表格...

I hope my story makes some sense. 我希望我的故事有意义。 Current code: 当前代码:

<?php
# Database connection
include('includes/database.php');

# Query
$query = "SELECT * FROM products LIMIT 25" or die(mysqli_error());
$result = mysqli_query($dbc, $query_left);

?>

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <!--Stylesheet-->
    <link rel="stylesheet" href="css/style.css">
</head>
<body>


    <div id="main">

        <div id="content">

            <div class="table">

            <form action="" method="post">

            <table class="products">


<?php
# Begin while-loop
while($product = mysqli_fetch_assoc($result)){
?>
    <tr>
        <td class="products">
            <?php echo $product['name']; ?>
        </td>
        <td>
            <input type="text" name="amount" id="amount" value="<?php echo $product['amount']; ?>" />
        </td>
    </tr>

<?php
# End while-loop
} 
?>

            </table>

            </form>

            </div>
        </div>
    </div>
</body>
</html>

Define a column with numeric input in database table as page count and add a form on the page to get the values of the pages numbers from the user : 在数据库表中定义一个带有数字输入的列作为页数,并在该页上添加一个表单以从用户获取页码的值:

Here is the html code to add a form to get the number of pages : 这是添加表单以获取页数的html代码:

<html> 
<body>

<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
Number of Pages : <input type="number" name="pagenumber" min="1" max="8"><br>
<input type="submit">
</form>

</body>
<html>

This will add the input number into the table with numeric value, now all you have to do is just call this number from the database when generating output file and you can also use the loop like if the user has entered 4 number in the input the loop will start from this number and will decrement to 0. This how you will be able to get your required feature. 这会将输入数字添加到带有数字值的表中,现在您所要做的只是在生成输出文件时从数据库中调用该数字,您还可以使用循环,就像用户在输入中输入4数字一样。循环将从该数字开始,并递减为0。这将使您能够获得所需的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM