php - ON DUPLICATE KEY UPDATE keeping some sold values -


ive googled 1½ hour , cant come understanding how this.

i want update current row, keep values assigned. have checkbox either gives "1" or "0". if checkbox returns "0" dont want update there's no point updating. dont know how this.

if col1 duplicate entry, should update col2,3,4,5 if entry isnt filled "1" or if variable gotten form "0".

i lot of if statements id prefer not to. , aware code extremely messy right because im trying find solution. code fixed when result want to. code written in mysql because im more familiar in , ported pdo when done. please dont tell me "dont use mysql" , dont give me answer. gotten enough

 $insert_movie = "insert filmer (namn, rel_720p, rel_1080p, rel_dvdr, swesub, addate)  values ('$namn','$rel_720p','$rel_1080p','$rel_dvdr','$swesub',current_timestamp)  on duplicate key update  rel_720p = if('$rel_720p' not null, '$rel_720p', rel_720p), rel_1080p = if('$rel_1080p' not null, '$rel_1080p', rel_1080p), rel_dvdr = values(rel_dvdr), swesub = values(swesub)";  $result = mysql_query($insert_movie, $connection) or die (mysql_error());  mysql_close($connection); 

pictures of whats happening: first entry: http://puu.sh/9in0p/91f0839b8f.png second entry: http://puu.sh/9in2q/8cafdb5422.png

look @ last row in there. first picture second should 1,1,1,1 , not 0,1,1,0.

probably not best solution, managed anyhow:

on duplicate key update rel_720p = if('$rel_720p'=1, 1, rel_720p), rel_1080p = if('$rel_1080p'=1, 1, rel_1080p), rel_dvdr = if('$rel_dvdr'=1, 1, rel_dvdr), swesub = if('$swesub'=1, 1, swesub)"; 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -