Welcome Guest, Not a member yet? Register   Sign In
Help with sql clauses <= or >=
#1

[eluser]samuelr[/eluser]
I'm trying to make a sql clause a search like this:

Code:
SELECT * FROM product WHERE produtos.preco >= 5
like this
Code:
$this->db->where('produtos.preco >=', $parameters);

in codeigniter 2.1.2 but is not working.

Could someone give me a hint, how to do this kind of sql?

Thank you
#2

[eluser]Beginers[/eluser]
better use this
Code:
$this->db->query("QUERY HERE");
#3

[eluser]Aken[/eluser]
That's the correct way to do it. Put $this->db->last_query() right after your query to see what is being created and why it's wrong.
#4

[eluser]johnpeace[/eluser]
[quote author="Beginers" date="1346142831"]better use this
Code:
$this->db->query("QUERY HERE");
[/quote]

No, do NOT do that.

Use the active record to construct your queries...that's what it's there for. (see the docs for all of the benefits).
#5

[eluser]johnpeace[/eluser]
[quote author="samuelr" date="1346113197"]
Code:
SELECT * FROM product WHERE produtos.preco >= 5
like this
Code:
$this->db->where('produtos.preco >=', $parameters);

in codeigniter 2.1.2 but is not working.

Could someone give me a hint, how to do this kind of sql?
[/quote]

What is the content of $parameters when the query runs?
#6

[eluser]samuelr[/eluser]
The $parameters is an integer.
You could tell me how to do this type of query without using
Code:
$this->db->query("QUERY HERE");
???
#7

[eluser]johnpeace[/eluser]
Sure,
Code:
$this->db->where('produtos.preco >=', $parameters)->get('produtos')->result();

The where() method simply adds the where clause to the query being constructed. You still have to execute the query and return the results.
#8

[eluser]Aken[/eluser]
[quote author="johnpeace" date="1346175803"][quote author="Beginers" date="1346142831"]better use this
Code:
$this->db->query("QUERY HERE");
[/quote]

No, do NOT do that.

Use the active record to construct your queries...that's what it's there for. (see the docs for all of the benefits).[/quote]
You can use either or. Nothing wrong with $this->db->query(), just takes a little more work to make secure.
#9

[eluser]samuelr[/eluser]
Thanks, problem solved.
The code
Code:
$this->db->where('produtos.preco >=', $parameters);
is working, the problem was that in the database, the field that was testing was as varchar. I switched to integer and it worked.

Thank you to all who helped.




Theme © iAndrew 2016 - Forum software by © MyBB