Php 使用数组的MySqlQuery
我需要有关此代码的帮助:Php 使用数组的MySqlQuery,php,mysql,arrays,echo,Php,Mysql,Arrays,Echo,我需要有关此代码的帮助: <?php include("config.php"); $Servico=implode(" ", $_POST['service']); $con=mysqli_connect("","","",""); //I hid the info here if (mysqli_connect_errno()) { echo "Falhou a conexão ao MySQL: " . mysqli_connect_error();
<?php
include("config.php");
$Servico=implode(" ", $_POST['service']);
$con=mysqli_connect("","","",""); //I hid the info here
if (mysqli_connect_errno())
{
echo "Falhou a conexão ao MySQL: " . mysqli_connect_error();
}
$to = mysqli_query($con,"SELECT Email FROM utilizadores WHERE Nome LIKE '%$Servico%'");
$row = mysqli_fetch_assoc($to);
$row['Email'];
foreach ($row as $destino)
{
echo $destino;
}
?>
有人能帮我吗?以下是如何使用中的
$con=mysqli_connect("","","",""); //I hid the info here
if (mysqli_connect_errno())
{
echo "Falhou a conexão ao MySQL: " . mysqli_connect_error();
}
$Servico=implode(", ", array_map(function($s) use ($con) {
return "'" . mysqli_real_escape_string($con, $s) . "'";
}, $_POST['service']));
$to = mysqli_query($con,"SELECT Email FROM utilizadores WHERE Nome IN ($Servico)");
while ($row = mysqli_fetch_assoc($to)){
echo $row['Email'];
}
$Row
仅包含一个元素,为什么需要循环?如果查询未找到任何匹配的行,则会发生此错误mysql\u fetch\u assoc
返回false
而不是数组。我使用的是Krish R的代码。如果数组包含一个用户,我会收到电子邮件,但如果有两个或更多用户,则会显示空白页。这是因为您的LIKE
表达式与其中任何一个都不匹配<代码>如“%foo bar baz%”
将只匹配其中完全包含foo bar baz
的内容,它本身不匹配任何内容。那么我该怎么做呢?在某些情况下,我有一个用户,但其他用户可能有10个,我需要检索1或10封电子邮件。它是否缺少一些代码?它在},$\u POST['service']上给我错误;抱歉,缺少一个括号。现在修复了第44行的/home/a5301436/public_html/criartarefa.php中的“解析错误:语法错误,意外的T_函数,预期为“)”你使用的是5.3以上的php吗?这就是添加匿名函数的时候。我使用的是PHP5.2版的临时服务器。我要换另一辆5.3的。我会尽快告诉你的。
$con=mysqli_connect("","","",""); //I hid the info here
if (mysqli_connect_errno())
{
echo "Falhou a conexão ao MySQL: " . mysqli_connect_error();
}
$Servico=implode(", ", array_map(function($s) use ($con) {
return "'" . mysqli_real_escape_string($con, $s) . "'";
}, $_POST['service']));
$to = mysqli_query($con,"SELECT Email FROM utilizadores WHERE Nome IN ($Servico)");
while ($row = mysqli_fetch_assoc($to)){
echo $row['Email'];
}