gpt4 book ai didi

mysql - 将 MySQL 获取数组查询转换为 redbean PHP

转载 作者:行者123 更新时间:2023-11-29 00:38:04 24 4
gpt4 key购买 nike

我有 2 个按钮,它们执行后期操作并设置一个隐藏变量,该变量用于设置 MySQL 查询以根据日期过滤数据库

if result = today

$query = "SELECT id,customer_name,CAST( `register_date` AS DATE ) AS dateonly,status,
DATE_FORMAT(book_date, '%m/%d/%y') FROM table WHERE book_date
BETWEEN (CURDATE() - INTERVAL 1 DAY) AND CURDATE()";


if result = week

$query = "SELECT id,customer_name,CAST( `register_date` AS DATE ) AS dateonly,status,
DATE_FORMAT(book_date, '%m/%d/%y') FROM table
WHERE book_date BETWEEN (CURDATE() - INTERVAL 7 DAY) AND CURDATE()";

然后我想用类似的东西

$result=mysql_query($query);
while ($mytable=mysql_fetch_array($result))
{
loop and display all the information in array in a table
}

但我需要相当于这个的红 bean 。

最佳答案

最简单的方法是将 $query 粘贴到 sql 函数中:

$results=R::getAll($query);
foreach($results as $row){
echo $row['id'];
}

下一种方法是手动构建查询....在我看来这可能只会让它看起来更草率:

$results=R::$f->begin()->select('id, customer_name, CAST( register_date AS DATE ) AS dateonly,status, DATE_FORMAT(book_date, '%m/%d/%y')')->from('table')->where('book_date BETWEEN (CURDATE() - INTERVAL 1 DAY) AND CURDATE())->get();

最后一种方式是通过redbean抓取结果,手动处理:

$results=R::find('table','book_date BETWEEN (CURDATE() - INTERVAL 7 DAY) AND CURDATE()');

然后遍历结果,在 php 中一路配置数据。

关于mysql - 将 MySQL 获取数组查询转换为 redbean PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13448740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com