我正在制作一个供我自己使用的个人脚本,我需要知道如何回应mysqli_query的结果.我的代码如下:
$conn = MysqLi_connect($servername,$username,$password,$dbname);
if(isset($_POST['commercial'])){
if (isset($_POST['0'])){
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 1 AND sent='a'";
$resultsd1 = MysqLi_query($conn,$sql);
echo $resultsd1;
}
if (isset ($_POST['1'])){
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 2 AND sent='a'";
$resultsd2 = MysqLi_query($conn,$sql);
echo $resultsd2;
}
if (isset($_POST['2'])){
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 3 AND sent='a'";
$resultsd3 = MysqLi_query($conn,$sql);
echo $resultsd3;
}
if (isset ($_POST['3'])){
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 4 AND sent='a'";
$resultsd4 = MysqLi_query($conn,$sql);
echo $resultsd4;
}
if (isset ($_POST['4'])){
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 5 AND sent='a'";
$resultsd5 = MysqLi_query($conn,$sql);
echo $resultsd5;
}
}
?>
最佳答案
如果你想要返回多行
原文链接:https://www.f2er.com/mysql/433501.htmlif (isset($_POST['0'])) {
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 1 AND sent='a'";
$resultsd1 = MysqLi_query($conn,$sql);
while ($row = MysqLi_fetch_assoc($resultsd1))
{
echo $row['email'];
}
}
如果只有1排
if (isset($_POST['0'])){
$sql = "SELECT email FROM CommercialEmails WHERE articleid = '$_POST[article]' AND dripid = 1 AND sent='a' LIMIT 1";
$resultsd1 = MysqLi_query($conn,$sql);
$row = MysqLi_fetch_assoc($resultsd1);
echo $row['email'];
}