带Where子句的CodeIgniter Select语句 [英] CodeIgniter Select Statement with Where clause
问题描述
我是CodeIgniter的新手,我只想知道如何从MySql Db(带有where子句的Select语句)查询,我知道可以从网上搜索它,但是每当尝试某些操作时,我都会出错,这真的很令人沮丧. Where子句中的字符串将来自用户输入.谢谢你们!
Hi I'm new to CodeIgniter and I just want to know How will I query from my MySql Db, a Select Statement with a where clause, I know it can be searched from the net but whenever I try something I get errors, It's really frustrating. The string in the Where clause will be coming from a User Input. Thanks guys!
推荐答案
您可以按照Mehedi-PSTU所述进行操作,但是您似乎对此并不陌生,因此这里提供了一些额外信息:
You can do as Mehedi-PSTU stated, however it seems as though you're a little new to this, so here's some extra information:
我将在这里大部分复制Mehedi-PSTU.
I'll copy Mehedi-PSTU for the most part here.
$this->get->where('column_name', $equals_this_variable);
$query = $this->db->get('table_name');
这会将查询对象存储在变量$ query中. 如果要将其转换为可用数组,只需执行以下操作即可.
This will store the query object in the variable $query. if you wanted to convert that to a usable array, you just perform to following.
$results = $query->result_array();
或者您可以像这样循环遍历它:
Or you can loop through it like this:
foreach($query->result_array() as $result){
// Perform some task here.
}
更好的甚至是完全的理解可能来自于:
A better or even full understanding can probably come from:
http://ellislab.com/codeigniter/user-guide/database/active_record.html
这篇关于带Where子句的CodeIgniter Select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!