dear all,
Can someone check my code and explain where I am going wrong.
I'm trying to delete ultiple records at the same time but I seem to only be able to delet on record each time I run the script.
<?
// delete images and text.php
//
// Define Database connection details
$dbHost = "xxx.xxx.xxx";
$dbUser = "xxxxxx";
$dbPass = "xxxxxx";
$dbName = "xxxxxx";
$chosen = "46,48";
$dir = "images/";
$imagename = ".image25.jpg,.image31.jpg";
$filename = explode(",", $imagename);
// Attempt to connect to MySQL server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
// If the connection was unsuccessful...
if (!$link)
{
// Report error
print "&comments=" . urlencode("Could not connect to server");
exit;
}
// Attempt to select database. If unsuccessfull...
if (!@mysql_select_db($dbName))
{
// Report error to Flash and exit
print "&comments=" . urlencode("Could not select $dbName database");
exit;
}
$id = explode (",", $chosen);
$query = "SELECT * FROM danimage ORDER BY ID";
// Execute query
$result = @($query);
// If query was okay AND we have at least 1 valid item...
if ($result && @mysql_num_rows($result) > 0)
{
// Initialise variables to hold text and image list items
$title = "";
$comments = "";
$imagelist = "";
// For each item returned from query...
while($row = mysql_fetch_array($result))
{
$i = 0;
if ($row['ID'] == $id[$i]){
$cool = $id[$i];
$sql = "DELETE FROM danimage WHERE ID='$cool'";
$query = mysql_query($sql) or die("Cannot delete record.<br>" . mysql_error());
$remove = unlink($dir.$filename[$i]);
$checking .= $dir . $filename[$i] . " ";
$i++;
}
}
// Output items
print "&imagelist=$imagelist";
print "&titles=$title";
print "&comments=$comments";
}
else
{
// no items were found
print "&comments=" . urlencode("No items were found in the database");
}
// Close link to MySQL server
mysql_close($link);
print "&imagename= $row";
print "&chosen= $chosen";
?>