在PHP中如何编写代码,以便在条件为真时可以获取所有行数据 [英] In PHP how to write code so that it can fetch all row data if condition is true
本文介绍了在PHP中如何编写代码,以便在条件为真时可以获取所有行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在php中如何编写代码,以便它可以获取所有行数据,如果条件为真,否则显示未找到消息但只有一次
什么我试过了:
<?php
$ res = mysqli_query($ conn, SELECT * FROM email WHERE too ='$ email');
$ product_count = mysqli_num_rows($ res);
$ row = mysqli_fetch_array($ res);
if($ product_count> 0){
foreach($ res as $ key => $ row) {
#code ...
if($ row ['status'] =='删除'){
#code ...
echo $ row ['message' ]。
}
其他
{
echonot found;
}
}
}
?>
此代码正确显示数据,但也显示其他部分,如果条件不匹配则显示其他部分等于找到的行数。如果rows = 4,那么part运行4次。对不起我的英语不好。请尽快回答我
解决方案
res = mysqli_query(
conn,SELECT * FROM email WHERE too ='
电子邮件');
in php how to write code so that it can fetch all row data if condition is true else display not found message but only one time
What I have tried:
<?php $res=mysqli_query($conn, "SELECT * FROM email WHERE too = '$email'"); $product_count = mysqli_num_rows ($res); $row=mysqli_fetch_array($res); if ($product_count > 0) { foreach ($res as $key => $row) { # code... if ($row['status'] == 'Delete') { # code... echo $row['message']; } else { echo "not found"; } } } ?>
this code properly display the data but also display else part and if condition not match then it displays else part equal to number of rows found. if rows = 4 then else part run 4 times. Sorry for my English. Please answer me as soon as possible
解决方案
res=mysqli_query(
conn, "SELECT * FROM email WHERE too = '
email'");
这篇关于在PHP中如何编写代码,以便在条件为真时可以获取所有行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文