首页 >  毕业设计知识  > 正文

php判断商品价格范围

 一般来说,同一类型商品的最低价格不能高于最高价格。本例通过对用户输入商品价格进行判断。
 
  因为通过表单提交的POST方法发送PHP处理页面,接受到的值都是string字符串类型。本例使用PHP中的字符串比较函数strcmp()进行判断。然后根据返回值的范围得到最终的判断结果。
 
  实例代码:
 
PHP
<?php
    if(!empty($_POST['low'])){
        $low = $_POST['low'];
        $high = $_POST['high'];
        $temp = strcmp($low,$high);
        if($temp == 0){
            echo "<script>alert('价格相等')</script>";
        }elseif($temp>0){
            echo "<script>alert('最低价格高于最高价格,提交失败')</script>";
 
        }else{
            echo "<script>alert('提交成功')</script>";
 
        }
    }
?>
 
<!doctype html>
<html lang="en">
<head>
</head>
<body>
    <div>
        <form action="" method="post">
            <div>
                <label for="">最低价格:</label> <input type="text" name="low" size="10">
            </div>
            <div>
                <label for="">最高价格:</label> <input type="text" name="high" size="10">
            </div>
            <input type="submit" value="提交">
        </form>
    </div>
</body>
</html>

以上是本题目部分介绍,若需要完整版或不符合您的要求,请联系客服QQ:242219979

上一篇:php用户动态创建新闻摘要

下一篇:php使用函数重复输出字符串