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

[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 :
$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

$query = $this->db->from('user')->blablabla->bla->limit($entryspersite,$offset)->get();
if($query !== FALSE) {
    $num_rows = $query->num_rows();
    $result = $query->result_array();

[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
->a lot of if else
->bla-bla joins
->bla-bla stuff
$num_rows = $query->num_rows();
+ then just the limit
+ 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

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.

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


if ($search) { $this->db->like }
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 :-(

[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 :-(

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:
$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...

[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.

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

if ($this->input->post(‘btnAfisNum’))
$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