Php 使用文件检查器搜索和删除数据库行

Php 使用文件检查器搜索和删除数据库行,php,mysql,database,file,erase,Php,Mysql,Database,File,Erase,您好,我正在尝试从“嵌入”字段获取文件路径,请使用该路径查看该路径中是否存在文件。如果文件不存在,则删除该条目。我正在运行一个游戏网站,下载游戏文件的脚本跳过了一些,这就像在4000个db的草堆中找到了一根针。感谢您的帮助。这是我的密码: <?php if(isset($_POST['clean'])) { $query = "SELECT * FROM games WHERE embed"; $result = mysql_query($query) or die ("no query"

您好,我正在尝试从“嵌入”字段获取文件路径,请使用该路径查看该路径中是否存在文件。如果文件不存在,则删除该条目。我正在运行一个游戏网站,下载游戏文件的脚本跳过了一些,这就像在4000个db的草堆中找到了一根针。感谢您的帮助。这是我的密码:

<?php
if(isset($_POST['clean'])) {
$query = "SELECT * FROM games WHERE embed";
$result = mysql_query($query) or die ("no query");

$result_array_path = array();
while($row = mysql_fetch_assoc($result))
{
    $result_array_path = $row;
}
$count = mysql_num_rows($result);
for($counter=0;$counter<$count;$counter++){
if (file_exists($result_array_path[$counter])){

}else{
    mysql_query("DELETE FROM games WHERE embed".$result_array_path[$counter]);
    echo $result_array_path[$counter]." ";
}
}
}
?>
谢谢你的帮助,尤其是加格伦

对于那些想知道该计划是否适用于我的网站的人:
我发现一个可能是您的问题:

$result_array_path = array();

while($row = mysql_fetch_assoc($result))
{
  // You want to append the row to the results array
  // instead of replacing the array each time, so []
  $result_array_path[] = $row['embed'];
  // That's assuming the table field containing the path is "embed"
}
您可以像这样迭代
$result\u array\u path
中的项目,而不是使用
mysql\u num\u rows

foreach($result_array_path as $path) {
  if(! file_exists($path)) {
    // Delete
    // You missed a = in the query too
    mysql_query("DELETE FROM games WHERE embed = '" . $path . "'");
  }
}

这应该可以让它正常工作。

您得到的输出是什么?什么都没有-页面只是重新加载没有outputI实现的代码,我得到一个错误警告:file_exists()希望参数1是字符串,数组given@user2030325哦,对不起,对了
$row
是数据库中的字段数组。您可能应该使用$row['embed'],现在就编辑答案。我运行了程序-没有错误,但它决定删除我数据库中的所有内容,而不是删除我想要删除的内容。重建数据库时会遇到一些小麻烦。
$result_array_path = array();

while($row = mysql_fetch_assoc($result))
{
  // You want to append the row to the results array
  // instead of replacing the array each time, so []
  $result_array_path[] = $row['embed'];
  // That's assuming the table field containing the path is "embed"
}
foreach($result_array_path as $path) {
  if(! file_exists($path)) {
    // Delete
    // You missed a = in the query too
    mysql_query("DELETE FROM games WHERE embed = '" . $path . "'");
  }
}