2016-04-25 12 views
0

ここでは、私のテーブル構造が
表である:ここで販売のMysqli選択クエリ

invoice_no prd_code quantity unit_price discount tax total_tax date delet 
    135   1   1   120   0  5  0  1/8/2016  1 
    135   1   1   120   0  5  0  1/8/2016  0 
    135   2   3   30   0  0  0  1/8/2016  0 
    135   3   1   165   0  5  0  1/8/2016  0 
    136   2   4   30   3  5  0  1/16/2016  0 
    136   1   2   120   0  0  5  1/16/2016  0 
    136   1   2   120   0  0  5  1/16/2016  1 
    136   1   2   120   0  0  5  1/16/2016  1 
    137   1   2   120   0  0  0  1/15/2016  0 
    137   1   2   120   0  0  0  1/15/2016  0 
    138   2   12   30   0  0  6  1/16/2016  0 
    138   3   10   165   0  0  6  1/16/2016  0 

私のHTMLコード

<input type = "date" id = "fmdte" name = "fmdte" class = "form-control" /> 
<input type = "date" id = "todate" name = "todate" class = "form-control" /> 
<input type = "text" id = "tax" name = "tax" class = "form-control" /> 
<input type = "submit" id = "ser" name = "ser" value = "Search" /> 

ここでは私のPHPコードです:

if (isset($_POST['ser'])) 
{ 
    $fmdt = $_POST['fmdte']; 
    $todt = $_POST['todate']; 
    $tax_ser = $_POST['tax']; 
    $purqry = $db->execute("select * from sales where date BETWEEN '$fmdt' and '$todt' and (tax='$tax_ser' OR total_tax='$tax_ser') and delet='0'"); //,order_no 
} 

このテーブル税金とその他の1つはtotal_taxの2つのフィールドがあります。税額欄は品目別税金を格納するために使用され、total_taxは請求書に合計税金を格納するために使用されます。
total_taxフィールド(!= 0)の値ストアがゼロとして保存されている場合、税項目(!= 0)のtotal_tax値をゼロとして保存すると、初期値は2です。 taxとtotal_taxフィールドに格納されるので、デフォルト値は0です。
私は項目は税とtotal_taxフィールドを組み合わせゼロ税を検索したい
検索方法税= 0とtotal_tax = 0

+0

...解決策を見つけるしかし、あなたはこの私を追加している理由は何 'returnd'フィールドは、テーブルのスキーマではありませんnクエリ? – itzmukeshy7

+0

自分のコードを更新してください。 – Sambhu

+0

テーブルフィールドのデータ型も共有します。 – itzmukeshy7

答えて

0

試してみましょう(> 0とtotal_tax> 0は、税を避ける)こと

if (isset($_POST['ser'])) 
    { 
     $fmdt = $_POST['fmdte']; 
     $todt = $_POST['todate']; 
     $tax_ser = $_POST['tax']; 

     //use concat when passing variable value 
     $purqry = $db->execute("select * from sales ". 
     "where (date BETWEEN '". $fmdt ."' and '". $todt ."') ". 
     "and (tax= ". $tax_ser ." OR total_tax= ". $tax_ser .") and delet='0' "); //,order_no 
    } 
+0

は動作しません.. – Sambhu

+0

phymyadminでまずSQLを試してから、そのクエリをPHPコードに適用してください – keronconk

0

私は

if (isset($_POST['ser'])) { 
    $fmdt = $_POST['fmdte']; 
    $todt = $_POST['todate']; 
    $tax_ser = $_POST['tax']; 
    if ($tax_ser == '0') { 
     $purqry = $db->execute("select * from sales where date BETWEEN '$fmdt' and '$todt' and (tax='$tax_ser' and total_tax='$tax_ser') and delet='0'"); 
    } 
    else { 
     $purqry = $db->execute("select * from sales where date BETWEEN '$fmdt' and '$todt' and (tax='$tax_ser' OR total_tax='$tax_ser') and delet='0'"); 
    } 
}