EditableGrid how to fetch rows from MySql in php

I am trying to do an editable grid table in order to modify directly.
There is a field which I need to list all of it content so that I can select one.
Look at my code

function fetch_pairs($mysqli,$query){
    if (!($res = $mysqli->query($query)))return FALSE;
    $rows = array();
    while ($row = $res->fetch_assoc()) {
        $first = true;
        $key = $value = null;
        foreach ($row as $val) {
            if ($first) { $key = $val; $first = false; }
            else { $value = $val; break; } 
        }
        $rows[$key] = $value;
    }
    return $rows;
}
$grid->addColumn('product_name', 'Product', 'string' , fetch_pairs($mysqli,'SELECT id, name FROM table_product'), true);

In my database I have two tables:
-table_add{id,product-name}
-table_product{id,name}

But the list is not appearing.
I am getting this error:
Could not load JSON from url ‘loaddata.php?db_tablename=table_add’

Any idea why ?
I am having the same problem of this thread
But in my case when I put limit 18 it is showing me not all the data but some…
in my table_product I have 29 rows but only 18 are shown…

see also http://www.dreamincode.net/forums/topic/402641-editablegrid-how-to-fetch-rows-from-mysql-in-php for what we already figured out.

you got the solution ?

I have a vague idea what the problem is.

1 Like

Ok, hope you will find out because we are in the same problem

A obligatory sidenote: your function when using PDO instead of mysqli:

function fetch_pairs($pdo,$query){
    return $pdo->query($query)->fetchAll(PDO::FETCH_KEY_PAIR);
}

Thank you colshrapnel it was the solution !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.