Hey you all !
Happy holidays !
I have 2 tables:
Ads
ad_id primary
...
..
Adimages
image_id primary
ad_id FK
......
.....
I make sure to link each ad to its multiple corresponding images,using this:
$ad_id1 = "";
if($ad_id1 != $ad_id){
$ad_id1 = $ad_id;
}
so ad_id=58 in Ad table,will have 3 corresponding images(3 Foreign keys ad_id=58) in Adimages
am tyring to edit a user ad that is linked to 3 images:
image1
image2
image3
If a user wants to replace the images with new ones,say replace all three with just one-image4
i run this query:
[php]
$query="UPDATE Adimages SET name='$newfile',type='$type',size='$size',path='$p ath' WHERE ad_id='$ad_id' ";
mysql_query($query,$conn);
[/php]
The result I get is:
image4
image4
image4
normal,since all the images have the same foreign key(ad_id) related to one primary key(ad_id) on which the WEHRE clause was based.
How can I update all those images with one image?
so the result will be:
image4
Basically,I need a function that deletes all old rows,then allow new inserts.If i delete,the ad_id reference to 3 images is lost and only inserts1 image instead of 3
I tried REPLACE,but it only inserted a fourth new row(may be i need an advanced REPLACE or some special INSERT approach !!!?)
Any help would be very much appreciated !
my gratitude in advance.