Welcome Guest, Not a member yet? Register   Sign In
database question -> get rows from complex query AND results in ONE query ?!
#1

[eluser]Richard Schumann[/eluser]
hi mates,

a question for the pros :

lets say you have a complex query with joins and like stuff in, and you wanna know the num_rows of it, BUT you need as well the get() after that . how to do that without write everything twice for the query ?!

i need the row_count to render the "older page" button - and i dont need the limited count...

so something like :
Code:
$this->db->from('user')->blablabla->bla->limit($entryspersite,$offset)->get()->result_array();
$rows_of_everything_what_match = $this->db->get()->num_rows();

after the get() i cant do that without write the full query again, and i dont wanna repeat myselft in code.
any common solution or something like last_query_without_get() function ?!

ty so m uch for help
#2

[eluser]danmontgomery[/eluser]
Code:
$query = $this->db->from('user')->blablabla->bla->limit($entryspersite,$offset)->get();
if($query !== FALSE) {
    $num_rows = $query->num_rows();
    $result = $query->result_array();
}
#3

[eluser]Richard Schumann[/eluser]
will give me an array with 10 rows and a rowcount of 10 ...

but i want an array with 10 rows and a rowcount of all 50.000 rows ...

so like this :

$query = $this->db->from('user')->bla-bla
->bla-bla
->bla-bla
->a lot of if else
->bla-bla joins
->bla-bla stuff
$num_rows = $query->num_rows();
+ then just the limit
->limit($entryspersite,$offset)
+ and the get
$result = $query->result_array();

but after the num_rows() OR the get()

the start of my querry is empty again so i have to repeat myself with the full long code
#4

[eluser]WanWizard[/eluser]
Don't think that's what the TS had in mind, as that will give you the number of rows in the result set (i.e. the limited number).

If I interpret the question correctly, this is about a pagination kind of issue, where you need to know the total row count of the table, and a limited set of records for the currently selected page.

Those are two different questions, which you can't answer in a single query.
#5

[eluser]Richard Schumann[/eluser]
but why ? i have one query what i can split like

$this->db->from(‘user’);
$this->db->num_rows();

if ($search) { $this->db->like }
$this->db->where
and so on

and finaly get();

so why i cant do before a limit a count and then a offset get ?! :-)

i wonder if big projects or maybe google repeat the full code just for a resultcount :-(
#6

[eluser]Richard Schumann[/eluser]
well then how professional guys do that ? they realy use 2 querys right ?
the other option is that i dont know the rows and just have a link to a result site whats empty then :-(
#7

[eluser]WanWizard[/eluser]
He, we're trying to help here, this attitude doesn't get you anywhere.

num_rows() gives you the number of rows in a result set, the result of a query. You don't actually HAVE a result set until AFTER you run the query. Or do you thing magic is involved?

If you want to know the number of rows in your user table, you can do:
Code:
$rows = $this->db->count_all('user');

You're not asking for a result count (noctrum told you how to do that), you are asking for two DIFFERENT results from ONE single query.

I strongly suggest you start RTFM. This looks like a good start...
#8

[eluser]Richard Schumann[/eluser]
maybe just my question was wrong or my english bad, what ever.
i expect just a better solution for this problem to solve it better - then your and also mine known solution.

i dont have to read the manual you just drop me standard code what i know without manuals...

there are some more crazy functions like $this->db->last_query();

so i expected something like "last build query without the get" ....

what ever thanks.
#9

[eluser]BoggTm[/eluser]
Hellow, I am new, and I have a problem: my datas are displated outside, not in the website
code:
$data = array();
$this->data[‘CONTENT’] = $this->load->view(‘Forms/FormCautareNum’, $data, TRUE);
$this->parser->parse(‘layout/base_template’,$this->data);

if ($this->input->post(‘btnAfisNum’))
{
$var=$this->input->post(‘textfield’);
$query = $this->db->query(“SELECT * FROM adaugare_firma WHERE Nume LIKE ‘%$var%’”)->result();
foreach($query as $q)
{
echo q->Nume;
echo q->Domeniu;
echo q->Subdomeniu;
echo q->produs;
}

and I want to parse those datas in my view form: FormCautareNum .... Can anyone help?




Theme © iAndrew 2016 - Forum software by © MyBB