我想显示 1 条记录而不是显示整个数据库,PHP
I want to display 1 record instead of displaying the whole Database, PHP
dbconnect.php
<form method="post" action="a.php">
<select name="taskOption" id="cust-id" onchange="showUser(this.value)">
<?php
include 'orderSelect.php';
echo '<option>View Order</option>';
while($row = mysqli_fetch_array($result)):;?>
<option value='<?php echo $row[0]; ?>'><?php echo $row[1]; echo " ";
echo $row[2]; ?></option>
<?php endwhile; ?>
</select>
</form>
a.php
<?php
include 'connect.php';
$q = intval($_GET['q']);
$sql = "SELECT id, firstname, lastname,productOne, quantity, price
FROM orderlist";
$result = mysqli_query($conn, $sql);
echo "<table >
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
$tquan = $row['quantity'];
$tprice = $row['price'];
$total = $tquan * $tprice;
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['productOne'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $total . "</td>";
echo "</tr>";
}
echo "</table>";
?>
我成功了。当从下拉列表中编辑 select 时,它会显示我想查看的记录/用户,但问题是它显示了整个数据库数据。我只想了解 selected 人的具体情况。任何想法如何解决这个问题?我会很感激。
当我从下拉列表select
时,我只想select编辑第一行
您的 SELECT 是您需要 select 的整个数据库。
例如:
$sql = "SELECT 'id' FROM Users WHERE username='$name'";
这是一个使用 WHERE 子句的例子。
除了上面说的。
你提到你只想要 1 条记录。
在您的查询末尾添加“LIMIT 1”
或
将'while'命令更改为'if'命令,它只会运行一次。
dbconnect.php
<form method="post" action="a.php">
<select name="taskOption" id="cust-id" onchange="showUser(this.value)">
<?php
include 'orderSelect.php';
echo '<option>View Order</option>';
while($row = mysqli_fetch_array($result)):;?>
<option value='<?php echo $row[0]; ?>'><?php echo $row[1]; echo " ";
echo $row[2]; ?></option>
<?php endwhile; ?>
</select>
</form>
a.php
<?php
include 'connect.php';
$q = intval($_GET['q']);
$sql = "SELECT id, firstname, lastname,productOne, quantity, price
FROM orderlist";
$result = mysqli_query($conn, $sql);
echo "<table >
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
$tquan = $row['quantity'];
$tprice = $row['price'];
$total = $tquan * $tprice;
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['productOne'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $total . "</td>";
echo "</tr>";
}
echo "</table>";
?>
我成功了。当从下拉列表中编辑 select 时,它会显示我想查看的记录/用户,但问题是它显示了整个数据库数据。我只想了解 selected 人的具体情况。任何想法如何解决这个问题?我会很感激。
当我从下拉列表select
时,我只想select编辑第一行您的 SELECT 是您需要 select 的整个数据库。
例如:
$sql = "SELECT 'id' FROM Users WHERE username='$name'";
这是一个使用 WHERE 子句的例子。
除了上面说的。 你提到你只想要 1 条记录。
在您的查询末尾添加“LIMIT 1”
或
将'while'命令更改为'if'命令,它只会运行一次。