前もって感謝します
データベース内の複数の画像を更新する際に問題があります。だから私は助けが必要です...私がしていることは次のとおりです。更新の場合、関数で画像データを取得し、デザインページでその関数を呼び出しています。この関数には、データから画像を取得するコードが含まれており、更新ページに画像を表示することはできますが、画像のいずれかが削除された場合に画像を更新することはできず、データを更新するため、以前の画像がデータベースで更新されます。前の画像が $_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");
}
}
}
}
}