我把这段代码改成了这个 <label for="from">时间:从</label> <input type="text" name="date_begin" id="from"/> <label for="to">到</label> <input type="text" name="date_end" id="to"/> 在写sql语句里面改了 sql = "select * from user where goods_types like ( '%".$_POST['goods_types']."%') or types like ('%".$_POST['types']."%') or (date_out > date_begin AND date_out < date_end)";对吗?感觉怪怪的,结果也不出来
if($_POST['goods_types'] != 'type') $w[] = "goods_types like '%{$_POST['goods_types']}%'"; if($_POST['types'] != 'types') $w[] = " types like '%{$_POST['types']}%'"; $w[2] = '(' . ($_POST['date_begin'] != '' ? "date_out > '{$_POST['date_begin']}' : '000-00-00'); $w[2] .= ' and '. ($_POST['date_end'] != '' ? "date_out < '{$_POST['date_end']}'" : now()) . ')'; $w = join(' or ', $w); $sql = "select * from user where $w"; 或 起来好像不对吧?
<input type="text" name="date_out" id="from"/>
<label for="to">到</label>
<input type="text" name="date_out" id="to"/>
<label for="from">时间:从</label>
<input type="text" name="date_begin" id="from"/>
<label for="to">到</label>
<input type="text" name="date_end" id="to"/>
在写sql语句里面改了
sql = "select * from user where goods_types like ( '%".$_POST['goods_types']."%') or types like ('%".$_POST['types']."%') or (date_out > date_begin AND date_out < date_end)";对吗?感觉怪怪的,结果也不出来
if($_POST['types'] != 'types') $w[] = " types like '%{$_POST['types']}%'";
$w[2] = '(' . ($_POST['date_begin'] != '' ? "date_out > '{$_POST['date_begin']}' : '000-00-00');
$w[2] .= ' and '. ($_POST['date_end'] != '' ? "date_out < '{$_POST['date_end']}'" : now()) . ')';
$w = join(' or ', $w);
$sql = "select * from user where $w";
或 起来好像不对吧?