gpt4 book ai didi

php - 选择一个选项以从数据库 MySQL 和 PHP 检索其行

转载 作者:行者123 更新时间:2023-11-29 18:28:31 24 4
gpt4 key购买 nike

我有一个表,它应该根据同一行中的选择从数据库中检索所有行。

HTML 和 PHP 代码

<div class="row">
<div class="table-responsive">
<table class="table table-bordered" id="tab_logic">
<thead>
<tr>
<th>Brand Name</th>
<th>Item Name</th>
<th>Model Number</th>
<th class="col-md-2">Item Description</th>
<th>Part Number</th>
<th>Unit</th>
<th class="col-md-1">QTY</th>
<th class="col-md-1">Unit Price (SR)</th>
<th class="col-md-1">Total Price (SR)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>Record</strong>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<div class="form-group">
<?php
$query = $con->query("SELECT products_itemDescription FROM pruc_products"); // Run your query --> For Item Desc.
echo '<select class="form-control" id="DescriptionS2forms" name="itemDescription">'; // Open your drop down box

echo '<option value="" selected="selected" disabled></option>'; //Empty Value for VALIDATION
// Loop through the query results, outputing the options one by one
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo '<option value="'.$row['products_itemDescription'].'">'.$row['products_itemDescription'].'</option>';
}
echo '</select>';// Close your drop down box
?>
</div>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<div>
<input class="form-control" type="number" name="requestQTY" required>
</div>
</td>
<td>
<div>
<input class="form-control" type="number" name="requestUnit" step="0.01" min="0.01" max="1000000" required>
</div>
</td>
<td>
<strong>Record</strong>
</td>
<td class="col-md-1" id="deleteBtn">
<a class="btn btn-default deleteBtn">Delete</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>

因此,我定义了此选择,它是从数据库中获取的,因此我还需要获取每个“记录”,但基于我将从选择选项卡中进行的选择。

PHP 和 SQL 查询

<?php
$sql = $con->prepare("SELECT products_brandName FROM pruc_products WHERE products_brandName, products_itemDescription = (products_id)") ;
$sql->execute() ;
while( $row = $sql->fetch()):
echo '<strong>'.$row['products_brandName'].'</strong>';
endwhile ?>

对此有什么帮助吗?

最佳答案

products_barndName 需要等于某些内容。另外,不要使用逗号来分隔 WHERE 子句中的条件。试试这个:

WHERE products_brandName = 'x' AND products_itemDescription = (products_id)

关于php - 选择一个选项以从数据库 MySQL 和 PHP 检索其行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45941380/

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