AdRock Posted August 27, 2006 Share Posted August 27, 2006 I am trying to make 3 comparisons and depending on what text fields have in them dpenedswhich SQL update to use. But will this code work?//if $event and $row['eventdate'] are the same and $pic and $row['photo'] are the same don't update the database and change their values but update the rest if (strcmp( $event,$row['eventdate'] ) =0) && (strcmp( $pic,$row['photo'] ) =0) { $query="UPDATE events SET title='$name', content='$message' WHERE id='$ud_id'"; mysql_query($query); }//if $event and $row['eventdate'] don't match and $pic and $row['photo'] are the same don't update $row['photo'] but update the rest elseif (strcmp( $event,$row['eventdate'] ) !=0) && (strcmp( $pic,$row['photo'] ) =0) { $query="UPDATE events SET title='$name', eventdate='$event', content='$message' WHERE id='$ud_id'"; mysql_query($query); }//if $event and $row['eventdate'] are the same and $pic and $row['photo'] don't match don't update $row['eventdate'] but update the rest else (strcmp( $event,$row['eventdate'] ) =0) && (strcmp( $pic,$row['photo'] ) !=0) { $query="UPDATE events SET title='$name', photo='$pic', content='$message' WHERE id='$ud_id'"; mysql_query($query); } Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/ Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 the else at the end cant have a condiition because it is used for any other condition, the guys will help u more so keep visiting ur post Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81250 Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 change it to an else if and have a blanck else(){} at the end Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81252 Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 else if are two seperate words Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81254 Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 $event,$row this dosent look right what are you trying to do is event an object in for its $event->row Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81257 Share on other sites More sharing options...
redarrow Posted August 27, 2006 Share Posted August 27, 2006 example 1elseif is the same as else if ok.[code]<?phpif(condition){elseif(condition){else if(condition){}else{(condition);}?>[/code]example 2[code]<?phpif(condition){do somethink}else{not done}?>[/code]example 3[code]<?phpif(conditon){if(condition){do some think if the two condition true}}else{if failed}?>[/code] Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81259 Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 try this[code]<?php if (strcmp($event,$row['eventdate']) == 0 && strcmp($pic,$row['photo']) == 0) { $query="UPDATE events SET title='$name', content='$message' WHERE id='$ud_id'"; mysql_query($query); } else if (strcmp($event,$row['eventdate']) !=0 && strcmp($pic,$row['photo']) == 0) { $query="UPDATE events SET title='$name', eventdate='$event', content='$message' WHERE id='$ud_id'"; mysql_query($query); } else if(strcmp($event,$row['eventdate']) == 0 && strcmp($pic,$row['photo']) !=0) { $query="UPDATE events SET title='$name', photo='$pic', content='$message' WHERE id='$ud_id'"; mysql_query($query); } else (){ }?>[/code] Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81261 Share on other sites More sharing options...
nadeemshafi9 Posted August 27, 2006 Share Posted August 27, 2006 if ur comparing strings u might wana try adding ' ' around the 0's Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81262 Share on other sites More sharing options...
redarrow Posted August 27, 2006 Share Posted August 27, 2006 please also read this ok.[code]It's definitely worth noting that the return-values of strcmp() when used for i.e. password-checking is the oposite of that of the ==-operator.<?php// I.e.:$pw1 = "yeah";$pw2 = "yeah";if (strcmp($pw1, $pw2)) { // This returns false. // $pw1 and $pw2 are NOT the same.} else { // $pw1 and $pw2 are the same.}//Where the use of the == operator would give us.:if ($pw1==$pw2) { // This returns true. // $pw1 and $pw2 are the same.} else { // $pw1 and $pw2 are NOT the same.}//Additionally, to check if $pw1 and $pw2 are of the same type you can use the === operator. <?[/code] Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81264 Share on other sites More sharing options...
redarrow Posted August 27, 2006 Share Posted August 27, 2006 my version[code]<?php if ((strcmp($event,$row['eventdate']=='0'))&&(strcmp($pic,$row['photo']) == '0'))) { $query="UPDATE events SET title='$name', content='$message' WHERE id='$ud_id'"; mysql_query($query); } else if ((strcmp($event,$row['eventdate'] !='0')) && (strcmp($pic,$row['photo']) == '0'))) { $query="UPDATE events SET title='$name', eventdate='$event', content='$message' WHERE id='$ud_id'"; mysql_query($query); } else if((strcmp($event,$row['eventdate'] == '0' ))&& (strcmp($pic,$row['photo']) !='0'))) { $query="UPDATE events SET title='$name', photo='$pic', content='$message' WHERE id='$ud_id'"; mysql_query($query); } else (){ }?>[/code] Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81270 Share on other sites More sharing options...
AdRock Posted August 27, 2006 Author Share Posted August 27, 2006 Thanks guys I managed to get it all working exactly how I want. it's nice to see people help so quickly and I do try and help others when i can :D Link to comment https://forums.phpfreaks.com/topic/18829-will-this-ifelseifelse-statement-work-resolved/#findComment-81286 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.