Jump to content


Photo

will this if/elseif/else statement work? [RESOLVED]


  • Please log in to reply
10 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 27 August 2006 - 08:21 PM

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);
    }

If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 27 August 2006 - 08:48 PM

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
DONT LAY AN EGG OVER IT

#3 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 27 August 2006 - 08:49 PM

change it to an else if and have a blanck else(){} at the end
DONT LAY AN EGG OVER IT

#4 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 27 August 2006 - 08:52 PM

else if are two seperate words
DONT LAY AN EGG OVER IT

#5 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 27 August 2006 - 08:56 PM

$event,$row this dosent look right what are you trying to do is event an object in for its $event->row
DONT LAY AN EGG OVER IT

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 August 2006 - 09:02 PM

example 1
elseif is the same as else if ok.
<?php

if(condition){

elseif(condition){

else if(condition){

}else{
(condition);
}
?>

example 2
<?php

if(condition){

do somethink

}else{

not done

}
?>


example 3

<?php

if(conditon){

if(condition){

do some think if the two condition true

}
}else{

if failed

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 27 August 2006 - 09:05 PM

try this

<?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 (){
	}
?>

DONT LAY AN EGG OVER IT

#8 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 27 August 2006 - 09:10 PM

if ur comparing strings u might wana try adding '  ' around the 0's
DONT LAY AN EGG OVER IT

#9 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 August 2006 - 09:13 PM

please also read this ok.


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. 

<?


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 August 2006 - 09:20 PM

my version
<?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 (){
	}
?>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 27 August 2006 - 09:46 PM

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
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users