Php 如何从数据库表中获取行的列
我有一个名为search.php的表单,用于搜索数据库列order\u nivPhp 如何从数据库表中获取行的列,php,mysql,database,Php,Mysql,Database,我有一个名为search.php的表单,用于搜索数据库列order\u niv <form class="form-inline justify-content-center my-5 subsribe-rounded" action="result.php" method="post"> <div class="form-group"> <input type="text" n
<form class="form-inline justify-content-center my-5 subsribe-rounded" action="result.php" method="post">
<div class="form-group">
<input type="text" name="order_inv" class="form-control px-4 u-rounded-50 u-h-55" placeholder="shipping number Ej:(AWB-100000001)" required>
</div>
<button type="submit" name="submit" class="btn btn-rounded btn-primary u-h-55">
Search Tracking
</button>
</form>
如果找到结果,我想获取我搜索的行中其他列的值。我做了这个$res=mysqli\u查询($connz,“从add\u courier中选择*,其中add\u courier
id=1”)代码>但它只显示一个固定的id,即使我没有搜索该行
从下面的图片。如果我搜索了AWB567890,我只想在圆圈中获得邮政、电子邮件、电话等的值
这是我的search.php
<form class="form-inline justify-content-center my-5 subsribe-rounded" action="result.php" method="post">
<div class="form-group">
<input type="text" name="order_inv" class="form-control px-4 u-rounded-50 u-h-55" placeholder="shipping number Ej:(AWB-100000001)" required>
</div>
<button type="submit" name="submit" class="btn btn-rounded btn-primary u-h-55">
Search Tracking
</button>
</form>
可能结果没有显示,因为您混淆了fetch_数组和fetch_assoc
使用fetch_数组,您可以对结果使用数字索引
$row = mysqli_fetch_array($res);
$res1 = $row[0];
$row = mysqli_fetch_assoc($res);
$res1 = $row['id'];
使用fetch_assoc,可以使用列名称作为结果的索引
$row = mysqli_fetch_array($res);
$res1 = $row[0];
$row = mysqli_fetch_assoc($res);
$res1 = $row['id'];
因此,result.php中的代码必须
$res = mysqli_query($connz,"SELECT * FROM add_courier WHERE `add_courier`.`id` = 1");
while($row=mysqli_fetch_assoc($res)){
$tracking = $row['tracking'];
$s_name = $row['s_name'];
$phone = $row['phone'];
$address = $row['address'];
$_SESSION['id'] = $row['id'];
}
否则,请尝试打印您的查询结果,以了解mysql是否没有返回它,或者它必须与您的php使用情况有关
var_dump($res);
或
如果您真的想查找order\u inv='AWxxx'
,为什么要指定id=1
?请参阅: