gpt4 book ai didi

mysql - 如何将普通的 mysql 查询转换为 codeigniter

转载 作者:行者123 更新时间:2023-11-29 19:28:08 25 4
gpt4 key购买 nike

我想从标记表中获得最高标记,但我已将获得的标记设置为 varchar 因为我想在某些情况下存储一些文本值。

当我在 mysql 中编写此内容时,它会以整数值形式返回最高标记

SELECT MAX(`mark_obtained`) AS `mark_obtained` FROM `mark` WHERE `exam_id` = '1' AND `class_id` = '10' AND `section_id` = '32' AND `subject_id` = '21' AND `mark_obtained` BETWEEN 0 AND 100

这是我编写的获得最高分数的codeigniter方法,但是当我给它打印值时,它总是打印varchar值

   function get_highest_marks($exam_id, $class_id, $section_id, $subject_id) {

$this->db->where('class_id', $class_id);
$this->db->where('section_id', $section_id);
$this->db->where('subject_id', $subject_id);
$this->db->where( "mark_obtained BETWEEN 0 AND 100", NULL, FALSE );

$highest_marks = $this->db->get('mark')->result_array();



foreach ($highest_marks as $row) {


echo $row['mark_obtained'];
}
}

那么如何始终打印最大整数值

最佳答案

function get_highest_marks($exam_id, $class_id, $section_id, $subject_id) {
$this->db->select('MAX(mark_obtained) AS mark_obtained');
$this->db->where('exam_id', $exam_id);
$this->db->where('class_id', $class_id);
$this->db->where('section_id', $section_id);
$this->db->where('subject_id', $subject_id);
$this->db->where('mark_obtained >=', 0);
$this->db->where('mark_obtained <=', 100);
$highest_marks = $this->db->get('mark')->result_array();
foreach($highest_marks as $key=>$val) {
echo $val = (int)$highest_marks[$key]['mark_obtained'];
}
}

function get_highest_marks($exam_id, $class_id, $section_id, $subject_id) {
$query = $this->db->query("SELECT MAX(mark_obtained) AS mark_obtained FROM mark
WHERE exam_id = '".$exam_id."' AND class_id = '".$class_id."' AND section_id
= '".$section_id."' AND subject_id = '".$subject_id."' AND mark_obtained
BETWEEN 0 AND 100");
if($query->num_rows() > 0){
$result = $query->row_array();
echo $result['mark_obtained'];
}
}

关于mysql - 如何将普通的 mysql 查询转换为 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41994518/

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