1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP...how to get the rest of a division

Discussion in 'PHP' started by lordadel, Oct 6, 2007.

  1. #1
    Hello

    i want a PHP code that can get me the rest of a division i want to know if a number is odd or even so i divide it into 2 if it is odd there will be a rest of the divison if it's even the rest of the division will be 0

    any ideas how can i do that?

    cheers
    Adel
     
    lordadel, Oct 6, 2007 IP
  2. tandac

    tandac Active Member

    Messages:
    337
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You're looking for the MODULO operator

    if ($x % 2 == 0) even

    the % operator returns the remainder from a division. It is always an integer
     
    tandac, Oct 6, 2007 IP
    lordadel likes this.
  3. lordadel

    lordadel Active Member

    Messages:
    1,035
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    90
    #3
    thanks alot for you reply

    rep + :)
     
    lordadel, Oct 6, 2007 IP
  4. lordadel

    lordadel Active Member

    Messages:
    1,035
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    90
    #4
    hmm another question if i want to redirect the page to another page if the number is even what should i do?
     
    lordadel, Oct 6, 2007 IP
  5. lordadel

    lordadel Active Member

    Messages:
    1,035
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    90
    #5
    there is another problem in this code because $count++ it doesnt count because the number isnot stored so i think we should store the number first then read it and then we make the increment

    because when i added echo "$count" ; it alwasy show 1 when i refresh the page
     
    lordadel, Oct 6, 2007 IP
  6. petronel

    petronel Peon

    Messages:
    113
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    you can try:
    
    session_start();
    session_register("count");
    
    if (!isset($_SESSION)) 
    {
    	$_SESSION["count"] = 1;
    } 
    else {
            $_SESSION["count"]++; 
    }
    
    if($_SESSION["count"] % 2) header( 'Location: http://www.yoursite.com/new_page.html' ) ;
    
    PHP:
     
    petronel, Oct 6, 2007 IP
  7. lordadel

    lordadel Active Member

    Messages:
    1,035
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    90
    #7
    thanks alot
     
    lordadel, Oct 6, 2007 IP