SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with some if/elseif conditionals

    Hi,

    I'm echoing out $Rversion, which right now is giving me 3.


    PHP Code:
    echo $Rversion;
            
    if(
    $Rversion=="1")
    {
    $SRupd "UPDATE sales_reps SET stage='2' status='Unclaimed' WHERE sr_id = '$sr' ";
    mysql_query($SRupd);
    }
    elseif(
    $Rversion=="2")
    {
    $SRupd "UPDATE sales_reps SET stage='5' status='Unclaimed' WHERE sr_id = '$sr' ";
    mysql_query($SRupd);
    }
    elseif(
    $Rversion=="3")
    {
    $SRupd "UPDATE sales_reps SET stage='6' status='Completed' WHERE sr_id = '$sr' ";
    mysql_query($SRupd);

    However, the final elseif is not running. It's running the if($Rversion=="1") every time.

    What am I doing wrong here? Thanks for any help.
    No, I REALLY dislike having to use Joomla.

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Personally I would use a switch() statement instead of if else:

    PHP Code:

    switch($Rversion) {

    case 
    1:
    $SRupd "UPDATE sales_reps SET stage='2' status='Unclaimed' WHERE sr_id = '$sr' "
    break;
    case 
    2:
    $SRupd "UPDATE sales_reps SET stage='5' status='Unclaimed' WHERE sr_id = '$sr' "
    break;
    case 
    3:
    $SRupd "UPDATE sales_reps SET stage='6' status='Completed' WHERE sr_id = '$sr' "
    break;
    }
    mysql_query($SRupd); 
    See if that makes a difference
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    Non-Member
    Join Date
    Feb 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    try this !

    try this , must work

    PHP Code:
    echo $Rversion
             
    if(
    $Rversion=="1"

    $SRupd "UPDATE sales_reps SET stage='2' status='Unclaimed' WHERE sr_id = '$sr' "
    mysql_query($SRupd); 

    if(
    $Rversion=="2"

    $SRupd "UPDATE sales_reps SET stage='5' status='Unclaimed' WHERE sr_id = '$sr' "
    mysql_query($SRupd); 

    elseif(
    $Rversion=="3"

    $SRupd "UPDATE sales_reps SET stage='6' status='Completed' WHERE sr_id = '$sr' "
    mysql_query($SRupd); 


  4. #4
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    spike - Thanks for the suggestion, but it's still not working.
    No, I REALLY dislike having to use Joomla.

  5. #5
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by publi-network View Post
    try this , must work

    PHP Code:
    echo $Rversion
             
    if(
    $Rversion=="1"

    $SRupd "UPDATE sales_reps SET stage='2' status='Unclaimed' WHERE sr_id = '$sr' "
    mysql_query($SRupd); 

    if(
    $Rversion=="2"

    $SRupd "UPDATE sales_reps SET stage='5' status='Unclaimed' WHERE sr_id = '$sr' "
    mysql_query($SRupd); 

    elseif(
    $Rversion=="3"

    $SRupd "UPDATE sales_reps SET stage='6' status='Completed' WHERE sr_id = '$sr' "
    mysql_query($SRupd); 

    it did not.
    No, I REALLY dislike having to use Joomla.

  6. #6
    derrrp
    Join Date
    Aug 2006
    Location
    earth
    Posts
    923
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    crap, nevermind.

    It wasn't my conditionals it was my sql.

    See? No commas...

    Thanks for the help anyway guys.
    No, I REALLY dislike having to use Joomla.

  7. #7
    Non-Member
    Join Date
    Feb 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no problem , ur welcome

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    LOL, would still go for a switch though
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •