dongzong8110 2017-07-14 14:17
浏览 37
已采纳

PHP过滤结果基于数据

I'm trying to filter some query results with a 'select' system. But I'm having zero success...

Here is the select code:

echo "<select name='period'>";
echo "<option value='select-period'>Select a period</option>";
echo "<option value='today'>Today</option>";
echo "<option value='7 days'>Last 7 days</option>";
echo "<option value='30 days'>Last month</option>";
echo "<option value='365 days'>Last year</option>";
echo "</select>";

Here is the query code:

$sqlCidade = "SELECT count( * ) FROM $table_name WHERE form_value REGEXP '.*\"city\";s:[0-9]+:\"$valorCidade\".'";

Everything works perfectly. But I need to filter the results based on the select options. I tried with an

AND form_date > current_date - interval '7 days'

at the end, but it didn't worked.

(form_date is the column on the db that has the posting date)

  • 写回答

1条回答 默认 最新

  • drrvnbwle80177811 2017-07-14 14:21
    关注

    Here you can use DATE_SUB() Mysql function check this func_mysql_date_sub

    And try like this

    echo "<select name='period'>";
    echo "<option value='select-period'>Select a period</option>";
    echo "<option value='1 DAY'>Today</option>";
    echo "<option value='7 DAY'>Last 7 days</option>";
    echo "<option value='30 DAY'>Last month</option>";
    echo "<option value='365 DAY'>Last year</option>";
    echo "</select>";
    
    AND form_date >DATE_SUB(current_date, INTERVAL 7 DAY)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python验证码滑块图像识别
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)