Select Menu and if else statments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LongWei
    New Member
    • Dec 2009
    • 6

    Select Menu and if else statments

    Hi all,


    i got small select menu with codes that goes

    Code:
     <select name="size" id="size" size ="2">
                  <option value="a">Less than 1 Megabyte</option>
                  <option value="b">&gt;1 Mb &lt; 10Mb</option>
                  <option value="c">More than 10 Megabyte</option>
                </select>
    However everytime when the form is click the option value is 'a' instead of 'b' regardless of option i select

    Code:
    if(isset($_POST['size']) && isset($_POST['criteria']) )
    {
    
    $size = $_POST['size'];
    
        if ($size = 'b') {$sizeq = "image_size < 1000000";}
    	else if ($size = 'a') {$sizeq = "image_size between 1000000 AND 10000000";}
    	else {$sizeq = "image_size > 10000000";}
    		
    mysql_select_db($database_ImageGallart, $ImageGallart);
     $query_rstImages =sprintf("SELECT * FROM image WHERE image_keywords LIKE  (".$sizeq.")");}
    any ideas why?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    Lines # 6 through 8. You need to use two = chars to compare values.

    [code=php]<?php
    $size = 'a';

    // If you do this:
    if($size = 'b') {
    echo 'This will always print, and $size will be set to "b" here after.';
    }

    // You should do:
    if($size == 'b') {
    echo 'This only prints if $size is "b", and the value is not altered.';
    }[/code]
    ?>

    Comment

    Working...