嗨我想從嵌入字段獲取文件路徑,使用該路徑查看文件是否存在於該路徑中。如果文件不存在,則刪除該條目。我正在運行一個遊戲網站,下載遊戲文件的腳本跳過了一些,所以它就像在4000條記錄的數據庫中找到針一樣。任何幫助表示讚賞。這裏是我的代碼:使用文件檢查器搜索和刪除數據庫行
<?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]." ";
}
}
}
?>
--------------編輯-------------
我更新的代碼BUT它決定刪除我的整個數據庫,而不是刪除缺少的遊戲條目。下面是修改後的代碼:
<?php
if(isset($_POST['clean'])) {
$query = "SELECT * FROM games WHERE embed NOT LIKE '%mochiads.com%'";
$result = mysql_query($query) or die ("no query");
$result_array_path = array();
while($row = mysql_fetch_assoc($result))
{
$result_array_path[] = $row['embed'];
}
foreach($result_array_path as $path) {
if(!file_exists($path)) {
mysql_query("DELETE FROM games WHERE embed = '" . $path . "'");
echo $path." | ";
}
}
}
?>
----------- --------------編輯
我調試的程序,所以它的工作原理現在。必須在程序中添加「$_SERVER['DOCUMENT_ROOT']
」。這裏是完成的程序
<?php
if(isset($_POST['clean'])) {
$query = "SELECT * FROM games WHERE embed NOT LIKE '%mochiads.com%'";
$result = mysql_query($query) or die ("no query");
$result_array_path = array();
while($row = mysql_fetch_assoc($result))
{
$result_array_path[] = $row['embed'];
}
foreach($result_array_path as $path) {
$rel_path = str_replace('http://www.flamegame.net', '', $path);
$rel_path = str_replace('http://flamegame.net', '', $rel_path);
$rel_path = str_replace('%20', ' ', $rel_path);
if(! file_exists($_SERVER['DOCUMENT_ROOT'] . $rel_path)) {
mysql_query("DELETE FROM games WHERE embed = '" . $path . "'");
echo $rel_path." | ";
}
}
}
?>
謝謝所有的幫助特別是加格龍。
對於那些誰不知道這個節目是我的網站: http://www.FlameGame.net
你得到的輸出是什麼? – Achrome 2013-02-10 22:24:29
什麼都沒有 - 頁面只是重新加載沒有輸出 – user2030325 2013-02-10 22:31:33