我在以下代码中遇到第30行错误的“数组到字符串转换”错误,但我找不到原因。
<?php
$find = $_GET['input'];
if($find == " ")
{
echo "<img src='dontmess,bro.png'><br>DON'T MESS<br>";
}
$findo = explode(" ",$_GET['input']);
$find = array_map('strtoupper', $findo);
$con = mysqli_connect("localhost", "%%%%", "****", "sites");
$field = "keywords";
foreach($find as $value)
{
$value = mysqli_query($con, "SELECT * FROM webinfo WHERE upper($field) LIKE '%$find%'");
$data = $value;
while($results = mysqli_fetch_assoc( $data ))
{
echo "<a href='" . $results['link'] . "'>" . $results['title'] . "</a>";
echo "<br> ";
echo $results['description'];
echo "<br>";
echo "<br>";
echo "<br>";
}
$anymatches=mysqli_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, no results. WHY!!!!<br><br>";
} else
{
echo $anymatches;
}
?>
答案 0 :(得分:5)
你的foreach
循环可能有点怀疑:
foreach($find as $value)
{
$value = mysqli_query($con,
"SELECT * FROM webinfo WHERE upper($field) LIKE '%$find%'");
$data = $value;
您在查询中使用$find
作为参数。好像你打算使用$value
,但是$value
会被覆盖,丢弃你从循环中获得的原始值。
以下内容可能有所帮助:
foreach($find as $value)
{
$db_query = mysqli_query($con,
"SELECT * FROM webinfo WHERE upper($field) LIKE '%$value%'");
while($results = mysqli_fetch_assoc( $db_query ))
{
... etc