hey all,
I've got a code in which one cell in each row in a mySQL table consists of file id's separatated by a semicolon (ex: 56;91;24;663). I am working on a function to delete a specific file, and part of that involves taking that file's id out of the cell.
Here is the code right now... I think it is very innefficient and perhaps even has a bug or two. Critique please?
Btw, $contentsFiles refers to the contents of that cell I'm talking about in the db.
if($contentsFiles != "") //if the folder is not currently empty
{
$filesArray = explode(";", $contentsFiles);
$length = count($filesArray);
$found = false;
$i=0;
while($found == false && $i < $length)
{
if($filesArray[$i] == $fid)
{
unset($filesArray[$i]);
$found = true;
}
$i++;
}
if($found == false)
echo "<META HTTP-EQUIV=Refresh CONTENT=0; URL=members.php>";
//rebuild the string
$newFiles = "";
for($j=0; $j<count($filesArray)+1; $j++)
{
if($filesArray[$j]!= "")
$newFiles .= $filesArray[$j] . ";";
}
$newFiles = substr($newFiles, 0, (strlen($newFiles)-1));
//save the new file
$query2 = "UPDATE accounts SET contentsFiles = '$newFiles' WHERE uid='$uid'";
$result = mysql_query($query2, $link) or die('Query failed: ' . mysql_error());
mysql_close($link); //close db
return;
}
}