我正在尝试实现一个功能,用户可以将“关键字”添加到csv文件中,然后PHP代码将遍历关键字以使用“LIKE”函数查找匹配项。
$row2 = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row2: <br /></p>\n";
$row2++;
echo "<table id='example1' class='table table-bordered table-hover dataTable' role='grid'>";
echo "<tr>";
echo "<th aria-controls='example1' aria-sort='ascending'> FilePath </th>";
echo "<th> HashValue </th>";
echo "<th> NameNoPath </th>";
echo "<th> FileExtension </th>";
echo "</tr>";
for ($c = 0; $c < $num; $c++) {
echo "1";
echo "Data is:" . $data[$c] . '<br><br>';
//$data[$c] = $tst;
$sql = "SELECT * FROM `hash` WHERE `HashValue` LIKE '$data[$c]' ";
echo $sql;
$result = mysqli_query($conn, $sql);
if ($result) {
while ($row2 = mysqli_fetch_assoc($result)) {
echo "TEST";
echo "<tr>";
echo "<td>" . $row2['Filename'] . '<br>';
echo "<td>" . $row2['HashValue'] . '<br>';
echo "<td>" . $row2['NameNoPath'] . '<br>';
echo "<td>" . $row2['FileExtension'] . '<br>';
echo "</tr>";
}
echo "</table>";
echo "2";
}
//echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
该代码适用于仅匹配的FIRST记录
我已将问题缩小到while ($row2 = mysqli_fetch_assoc($result))
循环。所有测试“回声”都完美地工作到那一点
为什么while循环没有正确执行?