• 10Nov

    By using arrays like lists, we can create dynamic lists that the user can choose from. We can also count this list and know how many items we have in it.
    Shirts, More shirts, and what size do you want again?
    You need flash to play this tutorial.
    This tutorial goes over the following goals:
    Commenting
    Counting an array
    Are things set?
    User Input and processing
    You can find this tutorial video on youtube here.
    Shirts, More shirts, and what size do you want again? Part 2
    You need flash to play this tutorial.
    This tutorial goes over the following goals:
    Commenting
    Counting an array
    Are things set?
    User Input and processing
    You can find this tutorial video on youtube here.

    Here are the sources used in this tutorial:
    tut005.php
    <?php
    //This is going to be a file about shirts
    $shirts = array();
    
    $shirts[] = "XS";
    $shirts[] = "S";
    
    $shirts[] = "M";
    
    echo "you can pick from ".count($shirts)." shirts, here are your options:";
    
    print_r($shirts);
    if(isset($_REQUEST['size'])){
    
    	$size = (int)$_REQUEST['size'];
    
    	if($size < 0){
    		$size =0;
    
    	}
    	if($size > count($shirts)-1){
    
    		$size = count($shirts)-1;
    	}
    
    }else{
    	$size = 2;
    }
    if(isset($_REQUEST['quant'])){
    
    	$quant = (int)$_REQUEST['quant'];
    
    	if($quant < 0){
    		$quant = 0;
    
    	}
    }else{
    	$quant = 0;
    }
    
    echo "<br />";
    
    //echo $size;
    echo "you ordered the shirt size:".$shirts[$size].' and you ordered '.$quant.' shirts in this size. Each shirt goes from small being 10 each to 50<br />'."\n";
    
    $cost = ($size+1)*10*$quant;
    
    echo "you order costs $cost.";
    if($cost > 40){
    
    	$cost = .95*$cost;
    echo " You just saved 5% and now it costs $cost";
    
    }
    
    ?>

    Here are all the php functions used in this tutorial:

    Posted by Kloplop321 @ 12:12 pm

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.