如何根据日期从数据库中排队数据

时间:2014-01-14 23:22:31

标签: php

我想确定客户订单的优先级。

示例:

  • customer1于2014年1月15日下订单。
  • customer2于2014年1月16日下订单。

在这种情况下,优先级为customer1。

<?php
    session_start();
    include('includes/config.php');

        $id2=$_SESSION['id'];   
        $name = $_POST['name'];
        $branch = $_POST['branch'];
        $transcode = $_POST['code'];

    $q = mysql_query("select * from cart where mem_id=$id2 and transactioncode='$transcode'");
    while($r = mysql_fetch_array($q)) {

                $category_desc=$r['category_desc'];
                $type=$r['type'];
                $images=$r['images'];
                $size=$r['size'];
                $qty=$r['qty'];
                $price=$r['price'];
                $total=$r['total'];
                $attach_files=$r['attach_files'];
                $dt_claimingR=$r['dt_claimingR'];
                $message=$r['message'];

            mysql_query("INSERT INTO reservation (`mem_id`,`name`,`branch`,`category_desc`,`type`,`images`,`size`,`qty`,`price`,`total`,`attach_files`,`dt_claimingR`,`message`,`WR_status`, `status`,`transactioncode`) 
                                    VALUES('$id2','$name','$branch','$category_desc','$type','$images','$size','$qty','$price','$total','$attach_files','$dt_claimingR','$message','Priority(<?php echo $count; ?>)','pending...','$transcode')")
                        or die(mysql_error());
    }
                        echo "success";
    ?>
    <script>
        window.location.href="layouting.php";
    </script>

1 个答案:

答案 0 :(得分:0)

假设datum是表格中的日期列,然后使用:

order by date asc/desc

e.g。

$q = mysql_query("select * from cart where mem_id=$id2 and 
transactioncode='$transcode' order by datum desc");

关于优先级:你需要表单(Get | POST)假设优先级的请求参数是p,可能的值是:a表示asc,d表示desc:

<?php
    $p = $_REQUEST['p'];
    $priority = 'asc'; //default value
    if($p == 'd') {
        $priority = 'desc';
    }
    $q = mysql_query("select * from cart where mem_id=$id2 and 
          transactioncode='$transcode' order by datum {$priority}");