gpt4 book ai didi

php - 如何根据 MySQL 值更改 PHP 中输​​入字段的数量?

转载 作者:行者123 更新时间:2023-11-29 20:55:37 25 4
gpt4 key购买 nike

我正在开发 PHP 网络应用程序。我有一个表格,其中包含单元格数量的值。

假设单元格=4。

我需要做的是 PHP 创建单元格数量的输入字段。

例如:

Cell #1: (input field)
Cell #2: (input field)
Cell #3: (input field)
Cell #4: (input field)

关键在于,随着单元格数量的变化,因此需要代码允许这一点。

我用谷歌搜索了一下,找不到任何关于如何做到这一点的信息。我知道我可以创建一个循环来创建输入框的数量,但是如何将输入字段左侧的文本与输入框一起创建?

最佳答案

//create a regular query (this one is in PDO, but it is just an example. just use your own and put a count on the results

$query = "SELECT * FROM your_table WHERE equal = to_equal";
$query = $db->query($query);
$query ->execute();
$query_fetch= $query ->fetchAll(PDO::FETCH_ASSOC);
//count the amount of rows
$query_fetch_count= count($query_fetch);
//amount of rows is now 4 for example

创建一个 for 循环来创建输入字段

    for ($i = 0; $i < $query_fetch_count; $i++) { 
echo "<input type='text'>"
}

EDIT

//something like this I believe. Putting the $i variable in the label and the input so it is equal to each other
//or use the $query_fetch if you want to use the data and not a number.

for ($i = 0; $i < $query_fetch_count; $i++) {
echo "<label for=".$i.">$i</label>;
echo "<input type='text' id='$i'>"
}

关于php - 如何根据 MySQL 值更改 PHP 中输​​入字段的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37651947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com