提前致谢
我在更新数据库中的多个图像时遇到问题。所以我需要帮助......我正在做的是:在更新的情况下,我正在检索函数中的图像数据并在设计页面中调用该函数。该功能包括从数据中获取图像的代码,能够在更新页面中显示图像,但如果删除任何一个图像然后更新数据,则无法更新图像,因此先前的图像正在数据库中更新,意味着要说以前的图像以数组的形式出现在 $_POST["AircraftImage"] 这里是下面的代码:-
public function getimageswithaircraftid ($AircarftID){
try{
// Query to retrieve Aircraft Images from database...
$query = mysql_query ("SELECT * FROM `aircraft_image` WHERE `Aircraft_ID` = '".$AircarftID."' ");
if (mysql_num_rows ($query) > 0){
$tabledata = '';
//$_POST["AircraftImage"] = array();
$tabledata = "<th>File Name</th><th></th><th>File Size</th><th>Image Preview</th><th>Delete</th>";
while ($execute = mysql_fetch_object ($query)){
$filepath = $execute->uploadpath;
$split = explode('/', $filepath);
$tabledata .= "<tr class=record><td>".$split[5]."</td>";
$tabledata .= "<td><input type=text name=AircraftImage[] value=".$split[5]."::".$execute->filesize. "></td>";
$tabledata .= "<td>".$execute->filesize."</td>";
$tabledata .= "<td><a target=_blank href=".$execute->uploadpath."><img src=".$execute->uploadpath." height=70 width=70 /></a></td>";
$tabledata .= "<td><a href=# id=".$execute->AircraftImageId." class=delbutton>
<img title=Delete src=images/delete.png ></a></td></tr>";
//$tabledata .= "<input type=text name=AircraftImage[] value=".$split[5]."::".$execute->filesize. ">";
}
print $tabledata;
}
}
catch(Exception $ex){
}
}
这是插入/更新图像的代码..
public function uploadimage ($AircraftImage = array()){
if (!$this->Aircraft_ID){
if (count ($AircraftImage) > 0){
//set_time_limit (240);
$q = mysql_query ("SELECT MAX(Aircraft_ID) as id FROM `aircraft` WHERE `IsDeleted` = 0 AND
`User_ID` = '".$this->User_ID."'");
$res = mysql_fetch_object ($q);
$maxid = $res->id;
foreach ($AircraftImage as $k=>$v){
$split = explode('::', $v);
$fullpath = "http://localhost/pz_serveroriginal/uploads/".$split[0];
//$fullpath = "http://pilotzeus.com/pz/uploads/".$split[0];
$filesize = $split[1];
// Insert into aircraft image with full path...
// select maxid from aircraft
$insert_query = mysql_query ("INSERT INTO `aircraft_image` (`Aircraft_ID`,`uploadpath`,`filesize`)
VALUES ('".$maxid."','".$fullpath."','".$filesize."')");
if ($insert_query == FALSE){
throw new Exception ("Some Error Occurred while Saving Images");
}
}
}
}
else{
if (count ($AircraftImage) > 0){
//DELETE ALL
$deletequery = mysql_query ("DELETE FROM `aircraft_image` WHERE `Aircraft_ID` = '".$this->Aircraft_ID."' ");
//set_time_limit (240);
foreach ($AircraftImage as $k=>$v){
$split = explode('::', $v);
$fullpath = "http://localhost/pz_serveroriginal/uploads/".$split[0];
//$fullpath = "http://pilotzeus.com/pz/uploads/".$split[0];
$filesize = $split[1];
//check if current image is not equal to database image then insert into database
// if image already exists or not
$insert_query = mysql_query ("INSERT INTO `aircraft_image` (`Aircraft_ID`,`uploadpath`,`filesize`)
VALUES('".$this->Aircraft_ID."','".$fullpath."','".$filesize."')");
if ($insert_query == FALSE){
throw new Exception ("Some Error Occurred while updating images");
}
}
}
}
}