dongxindu8753 2017-08-26 18:43
浏览 8

条件之间的多重选择给出错误的值

i want to ask about multiple select with between condition. i have made the code but i have got wrong callback value. in my php function i give two between condition, first between from date_awal and date_akhir and second from kode and kode_mat. but when i'm running the program i got wrong value from the date. (example : i want select date 21-08-2017 to 22-08-2017) when i'm running it i got it wrong value. i just got the data from 21-08-2017 only and the data from 22-08-2017 didn't showing, but when i change the date from 21-08-2017 to 22-08-2017 i can get the data. and something make me confuse i can get right value from between condition from kode1 and kode2. maybe someone can solve that. please help me

this is my php call function

<?php
include("../../Connections/koneksi.php");

$date_awal=$_POST['date_start'];
$date_akhir=$_POST['date_end'];
$kode=$_POST['kode_mat'];
$kode_mat=$_POST['kode_mate'];
$sloc=$_POST['s_loc'];
$s_loc=$_POST['s_loc1'];
$type=$_POST['get_type'];
//Display all data
$rows = array();
$sql = "SELECT * FROM wjm WHERE (date BETWEEN '$date_awal' AND '$date_akhir') AND (kode BETWEEN '$kode' AND '$kode_mat') order by kode asc";
$query = mysqli_query($db,$sql);

while($tmp= mysqli_fetch_assoc($query)) {
    $rows[] = $tmp;
}

echo json_encode($rows);

</div>
  • 写回答

1条回答 默认 最新

  • dpfln86244 2017-08-26 19:19
    关注

    See, if your columns in db are of type datetime then the date "22-08-2017" is actually "22-08-2017 00:00:00" That is the beginning of the day. Everything during the day is not included..

    so to handle it by 2 different ways:

    1.$sql = "SELECT * FROM wjm WHERE (DATE(date) BETWEEN '$date_awal' AND '$date_akhir') AND (DATE(kode) BETWEEN '$kode' AND '$kode_mat') order by kode asc";
    
    OR 
    
    2. $sql = "SELECT * FROM wjm WHERE date >= '$date_awal' AND date <= '$date_akhir' AND kode >= '$kode' AND kode <= '$kode_mat' order by kode asc";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏